let old_out = self.compressor.total_out();
let res = self
.compressor
- .compress(&inbuf[..], self.buffer.get_free_mut_slice(), flush)?;
+ .compress(inbuf, self.buffer.get_free_mut_slice(), flush)?;
let new_in = (self.compressor.total_in() - old_in) as usize;
let new_out = (self.compressor.total_out() - old_out) as usize;
self.buffer.add_size(new_out);
let params = parse_arguments(prefix, cli_cmd, args)?;
match cli_cmd.info.handler {
- ApiHandler::Sync(handler) => match (handler)(params, &cli_cmd.info, &mut rpcenv) {
+ ApiHandler::Sync(handler) => match (handler)(params, cli_cmd.info, &mut rpcenv) {
Ok(value) => {
if value != Value::Null {
println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
}
},
ApiHandler::Async(handler) => {
- let future = (handler)(params, &cli_cmd.info, &mut rpcenv);
+ let future = (handler)(params, cli_cmd.info, &mut rpcenv);
match future.await {
Ok(value) => {
let params = parse_arguments(prefix, cli_cmd, args)?;
match cli_cmd.info.handler {
- ApiHandler::Sync(handler) => match (handler)(params, &cli_cmd.info, &mut rpcenv) {
+ ApiHandler::Sync(handler) => match (handler)(params, cli_cmd.info, &mut rpcenv) {
Ok(value) => {
if value != Value::Null {
println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
}
},
ApiHandler::Async(handler) => {
- let future = (handler)(params, &cli_cmd.info, &mut rpcenv);
+ let future = (handler)(params, cli_cmd.info, &mut rpcenv);
if let Some(run) = run {
match (run)(future) {
Ok(value) => {
});
let err_msg = format!("no command specified.\nPossible commands: {}", list);
- print_nested_usage_error(&prefix, map, &err_msg);
+ print_nested_usage_error(prefix, map, &err_msg);
return Err(format_err!("{}", err_msg));
}
Some(cmd) => cmd,
None => {
let err_msg = format!("no such command '{}'", command);
- print_nested_usage_error(&prefix, map, &err_msg);
+ print_nested_usage_error(prefix, map, &err_msg);
return Err(format_err!("{}", err_msg));
}
};
match sub_cmd {
CommandLineInterface::Simple(cli_cmd) => {
//return handle_simple_command(&prefix, cli_cmd, args).await;
- return Ok(&cli_cmd);
+ return Ok(cli_cmd);
}
CommandLineInterface::Nested(new_map) => map = new_map,
}
let result = match &*def {
CommandLineInterface::Simple(ref cli_cmd) => {
- handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
+ handle_simple_command_future(prefix, cli_cmd, args, rpcenv).await
}
CommandLineInterface::Nested(ref map) => {
let mut prefix = prefix.to_string();
- let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
- handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
+ let cli_cmd = parse_nested_command(&mut prefix, map, &mut args)?;
+ handle_simple_command_future(&prefix, cli_cmd, args, rpcenv).await
}
};
let result = match &*def {
CommandLineInterface::Simple(ref cli_cmd) => {
- handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
+ handle_simple_command(prefix, cli_cmd, args, rpcenv, run)
}
CommandLineInterface::Nested(ref map) => {
let mut prefix = prefix.to_string();
- let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
- handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
+ let cli_cmd = parse_nested_command(&mut prefix, map, &mut args)?;
+ handle_simple_command(&prefix, cli_cmd, args, rpcenv, run)
}
};
if args[0] == "printdoc" {
let usage = match def {
CommandLineInterface::Simple(cli_cmd) => {
- generate_usage_str(&prefix, &cli_cmd, DocumentationFormat::ReST, "", &[])
+ generate_usage_str(&prefix, cli_cmd, DocumentationFormat::ReST, "", &[])
}
CommandLineInterface::Nested(map) => {
- generate_nested_usage(&prefix, &map, DocumentationFormat::ReST)
+ generate_nested_usage(&prefix, map, DocumentationFormat::ReST)
}
};
println!("{}", usage);
}
Schema::Array(ArraySchema { items, .. }) => {
if let Schema::String(_) = items {
- return get_property_completion(&items, name, completion_functions, arg, param);
+ return get_property_completion(items, name, completion_functions, arg, param);
}
}
_ => {}
record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
if args.len() > 1 {
if is_array_param {
- return get_simple_completion(cli_cmd, done, &arg_param[..], &args[1..]);
+ return get_simple_completion(cli_cmd, done, arg_param, &args[1..]);
} else {
return get_simple_completion(cli_cmd, done, &arg_param[1..], &args[1..]);
}
schema,
prop_name,
&cli_cmd.completion_functions,
- &prefix,
+ prefix,
done,
);
}
CommandLineInterface::Simple(cli_cmd) => {
let mut done: HashMap<String, String> = HashMap::new();
cli_cmd.fixed_param.iter().for_each(|(key, value)| {
- record_done_argument(&mut done, cli_cmd.info.parameters, &key, &value);
+ record_done_argument(&mut done, cli_cmd.info.parameters, key, value);
});
- get_simple_completion(cli_cmd, &mut done, &cli_cmd.arg_param, args)
+ get_simple_completion(cli_cmd, &mut done, cli_cmd.arg_param, args)
}
CommandLineInterface::Nested(map) => {
if args.is_empty() {
} else if output_format == "json" {
println!("{}", serde_json::to_string(&result).unwrap());
} else if output_format == "text" {
- if let Err(err) = value_to_text(std::io::stdout(), result, &return_type.schema, options) {
+ if let Err(err) = value_to_text(std::io::stdout(), result, return_type.schema, options) {
eprintln!("unable to format result: {}", err);
}
} else {
for i in 0..arg_param.len() {
let name = arg_param[i];
- if let Some((optional, param_schema)) = schema.lookup(&name) {
+ if let Some((optional, param_schema)) = schema.lookup(name) {
if i == arg_param.len() - 1 {
last_arg_param_is_optional = optional;
if let Schema::Array(_) = param_schema {
let args = vec!["-enable", "local"];
let res = parse_arguments(
&args,
- &vec!["storage"],
+ &["storage"],
&HashMap::new(),
ParameterSchema::from(&PARAMETERS),
);
let mut cells = Vec::new();
for entry in list.iter() {
let result = if let Some(renderer) = renderer {
- (renderer)(&entry[name], &entry)
+ (renderer)(&entry[name], entry)
} else {
data_to_text(&entry[name], prop_schema)
};
});
let result = if let Some(renderer) = renderer {
- (renderer)(&data[name], &data)
+ (renderer)(&data[name], data)
} else {
data_to_text(&data[name], prop_schema)
};
match def {
None => None,
Some(api_method) => {
- let description = wrap_text("", "", &api_method.parameters.description(), 80);
+ let description = wrap_text("", "", api_method.parameters.description(), 80);
let param_descr = dump_properties(&api_method.parameters, "", style, &[]);
let return_descr = dump_api_return_schema(&api_method.returns, style);
param: &HashMap<String, String>,
info: &dyn UserInformation,
) -> bool {
- if let Some(ref userid) = userid {
+ if let Some(userid) = userid {
if info.is_superuser(userid) {
return true;
}
}
Permission::Superuser => match userid {
None => return false,
- Some(ref userid) => return info.is_superuser(userid),
+ Some(userid) => return info.is_superuser(userid),
},
Permission::User(expected_userid) => match userid {
None => return false,
},
Permission::Group(expected_group) => match userid {
None => return false,
- Some(ref userid) => return info.is_group_member(userid, expected_group),
+ Some(userid) => return info.is_group_member(userid, expected_group),
},
Permission::WithParam(param_name, subtest) => {
return check_api_permission(
impl core::ops::Index<&str> for &dyn RpcEnvironment {
type Output = Value;
fn index(&self, index: &str) -> &Value {
- &self.result_attrib().index(index)
+ self.result_attrib().index(index)
}
}
impl core::ops::Index<&str> for &mut dyn RpcEnvironment {
type Output = Value;
fn index(&self, index: &str) -> &Value {
- &self.result_attrib().index(index)
+ self.result_attrib().index(index)
}
}
let mut optional_list: Vec<String> = Vec::new();
for (prop, optional, schema) in param.properties() {
- if skip.iter().find(|n| n == &prop).is_some() {
+ if skip.iter().any(|n| n == prop) {
continue;
}
let mut param_descr =
- get_property_description(prop, &schema, style, DocumentationFormat::ReST);
+ get_property_description(prop, schema, style, DocumentationFormat::ReST);
if !indent.is_empty() {
param_descr = format!("{}{}", indent, param_descr); // indent first line
.collect();
for value in list {
- match parse_simple_value(value.trim(), &array_schema.items) {
+ match parse_simple_value(value.trim(), array_schema.items) {
Ok(res) => array.push(res),
Err(err) => bail!("unable to parse array element: {}", err),
}
let additional_properties = schema.additional_properties();
for (key, value) in data {
- if let Some((_optional, prop_schema)) = schema.lookup(&key) {
+ if let Some((_optional, prop_schema)) = schema.lookup(key) {
match prop_schema {
Schema::Array(array_schema) => {
if params[key] == Value::Null {
}
match params[key] {
Value::Array(ref mut array) => {
- match parse_simple_value(value, &array_schema.items) {
+ match parse_simple_value(value, array_schema.items) {
Ok(res) => array.push(res), // fixme: check_length??
Err(err) => errors.push(key.into(), err),
}
}
}
Schema::Object(object_schema) => verify_json_object(data, object_schema)?,
- Schema::Array(array_schema) => verify_json_array(data, &array_schema)?,
- Schema::Boolean(boolean_schema) => verify_json_boolean(data, &boolean_schema)?,
- Schema::Integer(integer_schema) => verify_json_integer(data, &integer_schema)?,
- Schema::Number(number_schema) => verify_json_number(data, &number_schema)?,
- Schema::String(string_schema) => verify_json_string(data, &string_schema)?,
+ Schema::Array(array_schema) => verify_json_array(data, array_schema)?,
+ Schema::Boolean(boolean_schema) => verify_json_boolean(data, boolean_schema)?,
+ Schema::Integer(integer_schema) => verify_json_integer(data, integer_schema)?,
+ Schema::Number(number_schema) => verify_json_number(data, number_schema)?,
+ Schema::String(string_schema) => verify_json_string(data, string_schema)?,
Schema::AllOf(all_of_schema) => verify_json_object(data, all_of_schema)?,
}
Ok(())
schema.check_length(list.len())?;
for (i, item) in list.iter().enumerate() {
- let result = verify_json(item, &schema.items);
+ let result = verify_json(item, schema.items);
if let Err(err) = result {
let mut errors = ParameterError::new();
errors.add_errors(&format!("[{}]", i), err);
let additional_properties = schema.additional_properties();
for (key, value) in map {
- if let Some((_optional, prop_schema)) = schema.lookup(&key) {
+ if let Some((_optional, prop_schema)) = schema.lookup(key) {
let result = match prop_schema {
Schema::Object(object_schema) => verify_json_object(value, object_schema),
Schema::Array(array_schema) => verify_json_array(value, array_schema),
pub fn get_id_schema(&self) -> Option<&Schema> {
match &self.id_property {
Some(id_prop) => {
- if let Some((_, schema)) = self.properties.lookup(&id_prop) {
+ if let Some((_, schema)) = self.properties.lookup(id_prop) {
Some(schema)
} else {
None
let plugin = self.plugins.get(type_name).unwrap();
let id_schema = plugin.get_id_schema().unwrap_or(self.id_schema);
- if let Err(err) = parse_simple_value(§ion_id, &id_schema) {
+ if let Err(err) = parse_simple_value(section_id, id_schema) {
bail!("syntax error in section identifier: {}", err.to_string());
}
if section_id.chars().any(|c| c.is_control()) {
(self.parse_section_header)(line)
{
//println!("OKLINE: type: {} ID: {}", section_type, section_id);
- if let Some(ref plugin) = self.plugins.get(§ion_type) {
+ if let Some(plugin) = self.plugins.get(§ion_type) {
let id_schema =
plugin.get_id_schema().unwrap_or(self.id_schema);
if let Err(err) = parse_simple_value(§ion_id, id_schema) {
if let ParseState::InsideSection(plugin, ref mut section_id, ref mut config) = state
{
// finish section
- test_required_properties(&config, plugin.properties, &plugin.id_property)?;
+ test_required_properties(config, plugin.properties, &plugin.id_property)?;
if let Some(id_property) = &plugin.id_property {
config[id_property] = Value::from(section_id.clone());
}
- result.set_data(§ion_id, &plugin.type_name, config)?;
- result.record_order(§ion_id);
+ result.set_data(section_id, &plugin.type_name, config)?;
+ result.record_order(section_id);
}
Ok(())
content rootdir,images
";
- let res = config.parse(filename, &raw);
+ let res = config.parse(filename, raw);
println!("RES: {:?}", res);
let raw = config.write(filename, &res.unwrap());
println!("CONFIG:\n{}", raw.unwrap());
comment a very important group
";
- let res = config.parse(filename, &raw);
+ let res = config.parse(filename, raw);
println!("RES: {:?}", res);
let raw = config.write(filename, &res.unwrap());
println!("CONFIG:\n{}", raw.unwrap());
thinpool data
";
- let res = config.parse(filename, &raw);
+ let res = config.parse(filename, raw);
println!("RES: {:?}", res);
let created = config
.write(filename, &res.unwrap())