Document parsing and formatting functions.
Bug: 270547306
Test: m rust
Change-Id: I63c5550dda7a2010bdefb4b9329fc4d319c7aa23
diff --git a/system_properties/parsers_formatters.rs b/system_properties/parsers_formatters.rs
index b504c43..61b4cdb 100644
--- a/system_properties/parsers_formatters.rs
+++ b/system_properties/parsers_formatters.rs
@@ -9,13 +9,15 @@
// Parsers.
-#[allow(missing_docs)]
+/// Parses the given string as a `T`, or returns an error including the string value.
pub fn parse<T: FromStr>(s: &str) -> Result<T> {
s.parse::<T>()
.map_err(|_| format!("Can't convert '{}' to '{}'.", s, std::any::type_name::<T>()))
}
-#[allow(missing_docs)]
+/// Parses the given string as a boolean or returns an error message including the string.
+///
+/// `true` and `1` are both considered true, `false` and `0` are false. Any other value is invalid.
pub fn parse_bool(s: &str) -> Result<bool> {
match s {
"1" | "true" => Ok(true),
@@ -58,24 +60,28 @@
Ok(result)
}
-#[allow(missing_docs)]
+/// Parses the given string as a comma-separated list of `T`s.
+///
+/// Literal commas can be escaped with `\`.
pub fn parse_list<T: FromStr>(s: &str) -> Result<Vec<T>> {
parse_list_with(s, parse)
}
-#[allow(missing_docs)]
+/// Parses the given string as a comma-separated list of booleans.
+///
+/// Literal commas can be escaped with `\`.
pub fn parse_bool_list(s: &str) -> Result<Vec<bool>> {
parse_list_with(s, parse_bool)
}
// Formatters.
-#[allow(missing_docs)]
+/// Converts the given value to a string.
pub fn format<T: ToString>(v: &T) -> String {
v.to_string()
}
-#[allow(missing_docs)]
+/// Converts the given value to a string `true` or `false`.
pub fn format_bool(v: &bool) -> String {
if *v {
return "true".into();
@@ -83,7 +89,7 @@
"false".into()
}
-#[allow(missing_docs)]
+/// Converts the given value to a string `1` or `0`.
pub fn format_bool_as_int(v: &bool) -> String {
if *v {
return "1".into();
@@ -105,17 +111,17 @@
result
}
-#[allow(missing_docs)]
+/// Converts the given list of values to a string, separated by commas.
pub fn format_list<T: ToString>(v: &[T]) -> String {
format_list_with(v, format)
}
-#[allow(missing_docs)]
+/// Converts the given list of booleans to a string, separated by commas.
pub fn format_bool_list(v: &[bool]) -> String {
format_list_with(v, format_bool)
}
-#[allow(missing_docs)]
+/// Converts the given list of booleans to a string of `0`s and `1`s separated by commas.
pub fn format_bool_list_as_int(v: &[bool]) -> String {
format_list_with(v, format_bool_as_int)
}