Skip to main content

File

Struct File 

Source
pub struct File {
    pub path: PathBuf,
    pub section: FileSection,
}
Expand description

Structure representing a file path and its content.

Fields§

§path: PathBuf

File path.

§section: FileSection

File Section.

Implementations§

Source§

impl File

Source

pub fn from_template( path: impl AsRef<Path>, template: &SectionTemplate, ) -> Result<Self>

Creates a new file from a template.

Source

pub fn new(path: impl AsRef<Path>) -> Self

Creates a new file with the specified path and content.

Source

pub fn save(&self) -> Result<()>

Saves the file.

Methods from Deref<Target = FileSection>§

Source

pub fn indented_branch(&mut self, name: impl Into<String>) -> &mut Self

Gets or creates, if it doesn’t exist, an indented branch.

Source

pub fn indexed_write<S: Into<String>>(&mut self, index: usize, content: S)

Writes the content to the file section at the specified index.

Source

pub fn indexed_writeln<S: Into<String>>(&mut self, index: usize, content: S)

Writes the content to the file section at the specified index and adds a new line.

Source

pub fn write<S: Into<String>>(&mut self, content: S)

Writes the content to the file buffer.

Source

pub fn writeln<S: Into<String>>(&mut self, content: S)

Writes the content to the file buffer and adds a new line.

Source

pub fn indent(&mut self) -> &mut Self

Increase the indentation level by 1.

Source

pub fn dedent(&mut self) -> &mut Self

Decrease the indentation level by 1.

Source

pub fn indentation(&mut self, indentation_level: usize) -> &mut Self

Sets the indentation level.

Trait Implementations§

Source§

impl AsMut<FileSection> for File

Source§

fn as_mut(&mut self) -> &mut FileSection

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<FileSection> for File

Source§

fn as_ref(&self) -> &FileSection

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<FileSection> for File

Source§

fn borrow(&self) -> &FileSection

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<FileSection> for File

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl Debug for File

Source§

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

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

impl Deref for File

Source§

type Target = FileSection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for File

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl !RefUnwindSafe for File

§

impl !Send for File

§

impl !Sync for File

§

impl !UnwindSafe for File

§

impl Freeze for File

§

impl Unpin for File

§

impl UnsafeUnpin for File

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<'a, T> HasBranch<'a> for T

Source§

fn branch<T>(&'a mut self, segment: impl Into<String>) -> &'a mut T
where &'a mut Self: HasGet + HasBranches<&'a mut T>, Self: Sized + AddBranch<T> + HasGetMut<'a>, T: HasPathSegment + 'a, String: Into<T>,

Source§

impl<T> HasBranchesAPI for T

Source§

fn branches_impl2<T>(self) -> impl Iterator<Item = T>
where Self: Sized + HasBranches<T>,

This is used internally. Should use branches instead.
Source§

impl<'a, T> HasBranchesAPIV2<'a> for T

Source§

fn branches<T>(&'a self) -> impl Iterator<Item = T>
where &'a Self: HasBranches<T>, T: 'a,

Iterates over the branches of a type.
Source§

fn branches_mut<T>(&'a mut self) -> impl Iterator<Item = T>
where &'a mut Self: HasBranches<T>, T: 'a,

Iterates over the branches of a type mutably.
Source§

fn all_branches<T>(&'a self) -> impl Iterator<Item = T>
where &'a Self: HasBranches<T>, T: 'a + HasBranches<T> + Copy,

Source§

fn all_branches_mut<T>(&'a mut self) -> impl Iterator<Item = T>
where &'a mut Self: HasBranches<T>, T: 'a + HasBranches<T> + Copy,

Source§

impl<T> HasGet for T

Source§

fn get_impl<T>(self, segment: impl Into<String>) -> Option<T>
where Self: Sized + HasBranches<T>, T: HasPathSegment,

Gets a branch by its path segment. It’s discouraged to use this method directly. Instead, use the get and get_mut method from the HasGetAPI trait.
Source§

impl<'a, T> HasGetAPI<'a> for T

Source§

fn get<T>(&'a self, segment: impl Into<String>) -> Option<T>
where &'a Self: HasGet + HasBranches<T>, T: HasPathSegment + 'a,

Gets a branch by its path segment.
Source§

impl<'a, T> HasRelative<'a> for T

Source§

fn relative<K>(&'a self, path: impl IntoIterator<Item = K>) -> Option<Self>
where K: Into<String>, Self: KnowsVisitor<Visitor = Self> + Clone + HasRoot + HasParent + HasPathSegment, &'a Self: HasBranches<Self>,

Gets a relative path. “self”, “root”, and “super” are reserved path segments. “self” is the current object, “root” is the root object, and “super” is the parent object.
Source§

impl<'a, T> HasRelativeMut<'a> for T

Source§

unsafe fn relative_mut<K>( &'a mut self, path: impl IntoIterator<Item = K>, ) -> Option<Self>
where K: Into<String>, Self: Sized + KnowsVisitor<VisitorMut = Self> + UnsafeClone + HasRootMut + HasParentMut + HasPathSegment, &'a mut Self: HasBranches<Self>,

Gets a relative path mutably. “self”, “root”, and “super” are reserved path segments. “self” is the current object, “root” is the root object, and “super” is the parent object.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.