pub trait SerdeAPI: Serialize + for<'a> Deserialize<'a> {
const ACCEPTED_BYTE_FORMATS: &'static [&'static str] = _;
const ACCEPTED_STR_FORMATS: &'static [&'static str] = _;
const RESOURCE_PREFIX: &'static str = "";
const CACHE_FOLDER: &'static str = "";
Show 18 methods
// Provided methods
fn init(&mut self) -> Result<()> { ... }
fn list_resources() -> Vec<String> { ... }
fn from_resource<P: AsRef<Path>>(
filepath: P,
skip_init: bool,
) -> Result<Self> { ... }
fn to_file<P: AsRef<Path>>(&self, filepath: P) -> Result<()> { ... }
fn to_writer<W: Write>(&self, wtr: W, format: &str) -> Result<()> { ... }
fn from_file<P: AsRef<Path>>(filepath: P, skip_init: bool) -> Result<Self> { ... }
fn to_str(&self, format: &str) -> Result<String> { ... }
fn from_str<S: AsRef<str>>(
contents: S,
format: &str,
skip_init: bool,
) -> Result<Self> { ... }
fn from_reader<R: Read>(
rdr: R,
format: &str,
skip_init: bool,
) -> Result<Self> { ... }
fn to_json(&self) -> Result<String> { ... }
fn from_json<S: AsRef<str>>(json_str: S, skip_init: bool) -> Result<Self> { ... }
fn to_yaml(&self) -> Result<String> { ... }
fn from_yaml<S: AsRef<str>>(yaml_str: S, skip_init: bool) -> Result<Self> { ... }
fn to_toml(&self) -> Result<String> { ... }
fn from_toml<S: AsRef<str>>(toml_str: S, skip_init: bool) -> Result<Self> { ... }
fn from_url<S: AsRef<str>>(url: S, skip_init: bool) -> Result<Self> { ... }
fn to_cache<P: AsRef<Path>>(&self, file_path: P) -> Result<()> { ... }
fn from_cache<P: AsRef<Path>>(file_path: P, skip_init: bool) -> Result<Self> { ... }
}Provided Associated Constants§
const ACCEPTED_BYTE_FORMATS: &'static [&'static str] = _
const ACCEPTED_STR_FORMATS: &'static [&'static str] = _
const RESOURCE_PREFIX: &'static str = ""
const CACHE_FOLDER: &'static str = ""
Provided Methods§
Sourcefn list_resources() -> Vec<String>
fn list_resources() -> Vec<String>
List available (compiled) resources (stored in the rust binary)
§RESULT
vector of string of resource names that can be loaded
Sourcefn from_resource<P: AsRef<Path>>(filepath: P, skip_init: bool) -> Result<Self>
fn from_resource<P: AsRef<Path>>(filepath: P, skip_init: bool) -> Result<Self>
Read (deserialize) an object from a resource file packaged with the fastsim-core crate
§Arguments:
filepath- Filepath, relative to the top of theresourcesfolder (excluding any relevant prefix), from which to read the object
Sourcefn to_file<P: AsRef<Path>>(&self, filepath: P) -> Result<()>
fn to_file<P: AsRef<Path>>(&self, filepath: P) -> Result<()>
Write (serialize) an object to a file.
Supported file extensions are listed in ACCEPTED_BYTE_FORMATS.
Creates a new file if it does not already exist, otherwise truncates the existing file.
§Arguments
filepath- The filepath at which to write the object
fn to_writer<W: Write>(&self, wtr: W, format: &str) -> Result<()>
Sourcefn from_file<P: AsRef<Path>>(filepath: P, skip_init: bool) -> Result<Self>
fn from_file<P: AsRef<Path>>(filepath: P, skip_init: bool) -> Result<Self>
Read (deserialize) an object from a file.
Supported file extensions are listed in ACCEPTED_BYTE_FORMATS.
§Arguments:
filepath: The filepath from which to read the object
Sourcefn to_str(&self, format: &str) -> Result<String>
fn to_str(&self, format: &str) -> Result<String>
Write (serialize) an object into a string
§Arguments:
format- The target format, any of those listed inACCEPTED_STR_FORMATS
Sourcefn from_str<S: AsRef<str>>(
contents: S,
format: &str,
skip_init: bool,
) -> Result<Self>
fn from_str<S: AsRef<str>>( contents: S, format: &str, skip_init: bool, ) -> Result<Self>
Read (deserialize) an object from a string
§Arguments:
contents- The string containing the object dataformat- The source format, any of those listed inACCEPTED_STR_FORMATS
Sourcefn from_reader<R: Read>(rdr: R, format: &str, skip_init: bool) -> Result<Self>
fn from_reader<R: Read>(rdr: R, format: &str, skip_init: bool) -> Result<Self>
Deserialize an object from anything that implements std::io::Read
§Arguments:
rdr- The reader from which to read object dataformat- The source format, any of those listed inACCEPTED_BYTE_FORMATS
Sourcefn from_json<S: AsRef<str>>(json_str: S, skip_init: bool) -> Result<Self>
fn from_json<S: AsRef<str>>(json_str: S, skip_init: bool) -> Result<Self>
Read (deserialize) an object to a JSON string
§Arguments
json_str- JSON-formatted string to deserialize from
Sourcefn from_yaml<S: AsRef<str>>(yaml_str: S, skip_init: bool) -> Result<Self>
fn from_yaml<S: AsRef<str>>(yaml_str: S, skip_init: bool) -> Result<Self>
Read (deserialize) an object from a YAML string
§Arguments
yaml_str- YAML-formatted string to deserialize from
fn to_toml(&self) -> Result<String>
fn from_toml<S: AsRef<str>>(toml_str: S, skip_init: bool) -> Result<Self>
Sourcefn from_url<S: AsRef<str>>(url: S, skip_init: bool) -> Result<Self>
fn from_url<S: AsRef<str>>(url: S, skip_init: bool) -> Result<Self>
Instantiates an object from a url. Accepts yaml and json file types
§Arguments
- url: URL (either as a string or url type) to object
Note: The URL needs to be a URL pointing directly to a file, for example a raw github URL.
Sourcefn to_cache<P: AsRef<Path>>(&self, file_path: P) -> Result<()>
fn to_cache<P: AsRef<Path>>(&self, file_path: P) -> Result<()>
Takes an instantiated Rust object and saves it in the FASTSim data directory in
a rust_objects folder.
WARNING: If there is a file already in the data subdirectory with the
same name, it will be replaced by the new file.
§Arguments
- self (rust object)
- file_path: path to file within subdirectory. If only the file name is listed, file will sit directly within the subdirectory of the FASTSim data directory. If a path is given, the file will live within the path specified, within the subdirectory CACHE_FOLDER of the FASTSim data directory.
Sourcefn from_cache<P: AsRef<Path>>(file_path: P, skip_init: bool) -> Result<Self>
fn from_cache<P: AsRef<Path>>(file_path: P, skip_init: bool) -> Result<Self>
Instantiates a Rust object from the subdirectory within the FASTSim data directory corresponding to the Rust Object (“vehices” for a RustVehice, “cycles” for a RustCycle, and the root folder of the data directory for all other objects).
§Arguments
- file_path: subpath to object, including file name, within subdirectory.
If the file sits directly in the subdirectory, this will just be the
file name.
Note: This function will work for all objects cached using the to_cache() method. If a file has been saved manually to a different subdirectory than the correct one for the object type (for instance a RustVehicle saved within a subdirectory other than “vehicles” using the utils::url_to_cache() function), then from_cache() will not be able to find and instantiate the object. Instead, use the from_file method, and use the utils::path_to_cache() to find the FASTSim data directory location if needed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.