Skip to main content

File

Struct File 

Source
pub struct File<T, F>
where T: Merge,
{ /* private fields */ }
Available on crate feature file only.
Expand description

The File evaluator.

An Evaluator accompanied by its driving logic. If you are trying to use this crate, this is probably where you should be looking.

§Example

#[derive(Debug, PartialEq, Eq, serde::Deserialize, module::Merge)]
struct MyModule {
    a: Option<i32>,
    b: Option<Vec<usize>>,
}

let mut file: File<MyModule, format::Json> = File::default();

file.read(PathBuf::from("./module1.json")).unwrap();
file.read(PathBuf::from("./module2.json")).unwrap();

assert_eq!(file.finish(), Some(MyModule {
    a: Some(42),
    b: Some(vec![0, 1, 2, 3])
}));

Implementations§

Source§

impl<T, F> File<T, F>
where T: Merge,

Source

pub fn new(format: F) -> Self

Create a new File evaluator that reads modules based on format.

See: Format.

Source§

impl<T, F> File<T, F>
where T: Merge, F: Format<T>, F::Error: Send + Sync,

Source

pub fn read(&mut self, path: PathBuf) -> Result<(), Error>

Read the module from the file at path.

This method will evaluate path along with all of its imports. It should be used to declare only the root of the module tree.

§Example

See: File.

Source

pub fn finish(self) -> Option<T>

Destruct the evaluator and get the final value.

§Example

See: File.

Trait Implementations§

Source§

impl<T, F: Debug> Debug for File<T, F>
where T: Merge + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, F> Default for File<T, F>
where T: Merge, F: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, F> Freeze for File<T, F>
where F: Freeze, T: Freeze,

§

impl<T, F> RefUnwindSafe for File<T, F>

§

impl<T, F> Send for File<T, F>
where F: Send, T: Send,

§

impl<T, F> Sync for File<T, F>
where F: Sync, T: Sync,

§

impl<T, F> Unpin for File<T, F>
where F: Unpin, T: Unpin,

§

impl<T, F> UnsafeUnpin for File<T, F>
where F: UnsafeUnpin, T: UnsafeUnpin,

§

impl<T, F> UnwindSafe for File<T, F>
where F: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.