pub struct FmtWrapper<T>(pub T);Expand description
A wrapper around a type which will use the Display and FromStr implementations
for serialization / deserialization.
For example: u8, i8, i16, u16, all integer types… bool etc.
§Examples
use std::path::Path;
use dir_structure::traits::sync::DirStructureItem;
use dir_structure::fmt_wrapper::FmtWrapper;
#[derive(dir_structure::DirStructure, PartialEq, Debug)]
struct Dir {
#[dir_structure(path = "f.txt", with_newtype = FmtWrapper<u8>)]
f: u8,
#[dir_structure(path = "b.txt", with_newtype = FmtWrapper<bool>)]
b: bool,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let d = Path::new("dir");
std::fs::create_dir_all(&d)?;
std::fs::write(d.join("f.txt"), "42")?;
std::fs::write(d.join("b.txt"), "true")?;
let mut dir = Dir::read(&d)?;
assert_eq!(dir.f, 42);
assert_eq!(dir.b, true);
dir.f = 100;
dir.b = false;
dir.write(&d)?;
assert_eq!(std::fs::read_to_string(d.join("f.txt"))?, "100");
assert_eq!(std::fs::read_to_string(d.join("b.txt"))?, "false");
Ok(())
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T> AssertEq for FmtWrapper<T>
impl<T> AssertEq for FmtWrapper<T>
Source§impl<'a, 'vfs, T, Vfs> FromRefForWriter<'a, 'vfs, Vfs> for FmtWrapper<T>where
T: Display + 'a,
Vfs: 'vfs + WriteSupportingVfs<'vfs>,
'vfs: 'a,
impl<'a, 'vfs, T, Vfs> FromRefForWriter<'a, 'vfs, Vfs> for FmtWrapper<T>where
T: Display + 'a,
Vfs: 'vfs + WriteSupportingVfs<'vfs>,
'vfs: 'a,
Source§impl<'a, T, Vfs: WriteSupportingVfsAsync + 'static> FromRefForWriterAsync<'a, Vfs> for FmtWrapper<T>
Available on crate feature async only.
impl<'a, T, Vfs: WriteSupportingVfsAsync + 'static> FromRefForWriterAsync<'a, Vfs> for FmtWrapper<T>
Available on crate feature
async only.Source§type Wr = FmtWrapperRefWr<'a, 'a, T, Vfs>
type Wr = FmtWrapperRefWr<'a, 'a, T, Vfs>
The reference type to cast to.
Source§fn from_ref_for_writer_async(value: &'a Self::Inner) -> Self::Wr
fn from_ref_for_writer_async(value: &'a Self::Inner) -> Self::Wr
Casts the reference to the inner type to a
WriteToAsync
reference type.Source§impl<T> NewtypeToInner for FmtWrapper<T>
impl<T> NewtypeToInner for FmtWrapper<T>
Source§impl<'a, T, Vfs: Vfs<'a>> ReadFrom<'a, Vfs> for FmtWrapper<T>
impl<'a, T, Vfs: Vfs<'a>> ReadFrom<'a, Vfs> for FmtWrapper<T>
Source§impl<'a, T, Vfs: VfsAsync + 'static> ReadFromAsync<'a, Vfs> for FmtWrapper<T>
Available on crate feature async only.
impl<'a, T, Vfs: VfsAsync + 'static> ReadFromAsync<'a, Vfs> for FmtWrapper<T>
Available on crate feature
async only.Source§impl<'vfs, T, Vfs: WriteSupportingVfs<'vfs>> WriteTo<'vfs, Vfs> for FmtWrapper<T>where
T: Display,
impl<'vfs, T, Vfs: WriteSupportingVfs<'vfs>> WriteTo<'vfs, Vfs> for FmtWrapper<T>where
T: Display,
Source§impl<'a, T, Vfs: WriteSupportingVfsAsync + 'static> WriteToAsync<'a, Vfs> for FmtWrapper<T>
Available on crate feature async only.
impl<'a, T, Vfs: WriteSupportingVfsAsync + 'static> WriteToAsync<'a, Vfs> for FmtWrapper<T>
Available on crate feature
async only.Source§type Future = <FileString as WriteToAsync<'a, Vfs>>::Future
type Future = <FileString as WriteToAsync<'a, Vfs>>::Future
The future type returned by the async write function.
Source§impl<'a, T, Vfs: WriteSupportingVfsAsync + 'static> WriteToAsyncRef<'a, Vfs> for FmtWrapper<T>
Available on crate feature async only.
impl<'a, T, Vfs: WriteSupportingVfsAsync + 'static> WriteToAsyncRef<'a, Vfs> for FmtWrapper<T>
Available on crate feature
async only.Source§type Future<'b> = <FileString as WriteToAsync<'b, Vfs>>::Future
where
Self: 'b,
Vfs: 'b,
'a: 'b
type Future<'b> = <FileString as WriteToAsync<'b, Vfs>>::Future where Self: 'b, Vfs: 'b, 'a: 'b
The future type returned by the async write function.
Auto Trait Implementations§
impl<T> Freeze for FmtWrapper<T>where
T: Freeze,
impl<T> RefUnwindSafe for FmtWrapper<T>where
T: RefUnwindSafe,
impl<T> Send for FmtWrapper<T>where
T: Send,
impl<T> Sync for FmtWrapper<T>where
T: Sync,
impl<T> Unpin for FmtWrapper<T>where
T: Unpin,
impl<T> UnwindSafe for FmtWrapper<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DirStructureItem for T
impl<T> DirStructureItem for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more