[−][src]Trait sml::Small
Data-structures that implement the Small
trait can be constructed from a Small
formatted
string.
Required methods
fn from_data(data: Data) -> Result<Self, SmallError> where
Self: Sized,
Self: Sized,
The from_data()
function describes how to create a data-structure from the internal
components of the input String
. It maps a selection from the original input String
to
Self
. For example,
use small::{Data, Small, SmallError}; #[derive(Debug)] struct Hobbit { name: String, age: u32, friends: Vec<Hobbit>, bicycle: Option<String>, } impl Small for Hobbit { fn from_data(data: Data) -> Result<Self, SmallError> { Ok(Self { name: String::sml(&data, "hobbit::name")?, age: u32::sml(&data, "hobbit::age")?, friends: Vec::<Hobbit>::sml(&data, "hobbit::friends::hobbit")?, bicycle: Option::<String>::sml(&data, "hobbit::bicycle")?, }) } } fn main() { let s = r#" hobbit: name: "Frodo Baggins" age: "98" friends: hobbit: name: "Bilbo Baggins" age: "176" hobbit: name: "Samwise Gamgee" age: "66""#; let frodo = Hobbit::from_str_debug(s); }
Provided methods
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
Self: Sized,
Applies a keypath to Data
and returns a Vec
of Data
. For example applying
"hobbit::name"
to
hobbit:
name: "Frodo Baggins"
age: "98"
friends:
hobbit:
name: "Bilbo Baggins"
age: "176"
hobbit:
name: "Samwise Gamgee"
age: "66""#;
returns a Vec
with one Data
element,
name: "Frodo Baggins"
Applying "hobbit::name::friends"
to the original string returns a Vec
with two Data
elements which represent
hobbit:
name: "Bilbo Baggins"
age: "176"
and
hobbit:
name: "Samwise Gamgee"
age: "66""#;
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
Self: Sized,
Converts a String
into Self
.
fn from_str_debug(s: &str) -> Self where
Self: Sized,
Self: Sized,
Converts a String
into Self
. This function is designed to give helpful error messages
for debugging.
Implementations on Foreign Types
impl Small for String
[src]
Converts a Vec
of one Data
element to a String
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
impl Small for u32
[src]
Converts a Vec
with one Data
element to a u32
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
impl Small for usize
[src]
Converts a Vec
with one Data
element to a usize
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
impl Small for f32
[src]
Converts a Vec
with one Data
element to a f32
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
impl Small for bool
[src]
Converts a Vec
with one Data
element to a bool
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
impl<T> Small for Option<T> where
T: Small,
[src]
T: Small,
Converts a Vec
with either one or no Data
elements to an Option<T>
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
impl<T> Small for Vec<T> where
T: Small,
[src]
T: Small,
Converts a Vec
of Data
elements to a Vec<T>
.
fn from_data(data: Data) -> Result<Self, SmallError>
[src]
fn sml(data: &Data, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,