pub struct ContentString { /* private fields */ }Expand description
Holds the notes content in a string and two string slices
header and body.
This struct is self referential.
It deals with operating system specific handling of newlines.
The content of a note is stored as UTF-8 string with
one \n character as newline. If present, a Byte Order Mark
BOM is removed while reading with new().
Implementations§
Source§impl ContentString
impl ContentString
Sourcepub fn new(
owner: String,
dependent_builder: impl for<'_q> FnOnce(&'_q String) -> ContentRef<'_q>,
) -> Self
pub fn new( owner: String, dependent_builder: impl for<'_q> FnOnce(&'_q String) -> ContentRef<'_q>, ) -> Self
Constructs a new self-referential struct.
The provided owner will be moved into a heap allocated box. Followed by construction
of the dependent value, by calling dependent_builder with a shared reference to the
owner that remains valid for the lifetime of the constructed struct.
Sourcepub fn try_new<Err>(
owner: String,
dependent_builder: impl for<'_q> FnOnce(&'_q String) -> Result<ContentRef<'_q>, Err>,
) -> Result<Self, Err>
pub fn try_new<Err>( owner: String, dependent_builder: impl for<'_q> FnOnce(&'_q String) -> Result<ContentRef<'_q>, Err>, ) -> Result<Self, Err>
Constructs a new self-referential struct or returns an error.
Consumes owner on error.
Sourcepub fn try_new_or_recover<Err>(
owner: String,
dependent_builder: impl for<'_q> FnOnce(&'_q String) -> Result<ContentRef<'_q>, Err>,
) -> Result<Self, (String, Err)>
pub fn try_new_or_recover<Err>( owner: String, dependent_builder: impl for<'_q> FnOnce(&'_q String) -> Result<ContentRef<'_q>, Err>, ) -> Result<Self, (String, Err)>
Constructs a new self-referential struct or returns an error.
Returns owner and error as tuple on error.
Sourcepub fn borrow_owner<'_q>(&'_q self) -> &'_q String
pub fn borrow_owner<'_q>(&'_q self) -> &'_q String
Borrows owner.
Sourcepub fn with_dependent<'outer_fn, Ret>(
&'outer_fn self,
func: impl for<'_q> FnOnce(&'_q String, &'outer_fn ContentRef<'_q>) -> Ret,
) -> Ret
pub fn with_dependent<'outer_fn, Ret>( &'outer_fn self, func: impl for<'_q> FnOnce(&'_q String, &'outer_fn ContentRef<'_q>) -> Ret, ) -> Ret
Calls given closure func with a shared reference to dependent.
Sourcepub fn with_dependent_mut<'outer_fn, Ret>(
&'outer_fn mut self,
func: impl for<'_q> FnOnce(&'_q String, &'outer_fn mut ContentRef<'_q>) -> Ret,
) -> Ret
pub fn with_dependent_mut<'outer_fn, Ret>( &'outer_fn mut self, func: impl for<'_q> FnOnce(&'_q String, &'outer_fn mut ContentRef<'_q>) -> Ret, ) -> Ret
Calls given closure func with an unique reference to dependent.
Sourcepub fn borrow_dependent<'_q>(&'_q self) -> &'_q ContentRef<'_q>
pub fn borrow_dependent<'_q>(&'_q self) -> &'_q ContentRef<'_q>
Borrows dependent.
Sourcepub fn into_owner(self) -> String
pub fn into_owner(self) -> String
Consumes self and returns the the owner.
Trait Implementations§
Source§impl AsRef<str> for ContentString
Returns the whole raw content with header and body.
Possible \r\n in the input are replaced by \n.
impl AsRef<str> for ContentString
Returns the whole raw content with header and body.
Possible \r\n in the input are replaced by \n.
Source§impl Content for ContentString
Add header() and body() implementation.
impl Content for ContentString
Add header() and body() implementation.
Source§fn from_string(input: String, name: String) -> Self
fn from_string(input: String, name: String) -> Self
---. When the start marker
--- does not follow directly the BOM, it must be prepended
by an empty line. In this case all text before is ignored:
BOM + ignored text + empty line + ---.
Contract: the input string does not contain \r\n. If
it may, use Content::from_string_with_cr() instead. Read moreSource§fn open(path: &Path) -> Result<Self, Error>where
Self: Sized,
fn open(path: &Path) -> Result<Self, Error>where
Self: Sized,
path and stores the content
Content. Possible \r\n are replaced by \n.
This trait has a default implementation, the empty content. Read moreSource§fn from_string_with_cr(input: String, name: String) -> Self
fn from_string_with_cr(input: String, name: String) -> Self
\r\n are converted to \n if there are any.
If not no memory allocation occurs and the buffer remains untouched. Read moreSource§fn from_html(input: String, name: String) -> Result<Self, InputStreamError>
fn from_html(input: String, name: String) -> Result<Self, InputStreamError>
<!DOCTYPE html...> it is
automatically prepended.
If the input starts with another DOCTYPE than HTMl, return
InputStreamError::NonHtmlDoctype. Read moreSource§fn save_as(&self, new_file_path: &Path) -> Result<(), Error>
fn save_as(&self, new_file_path: &Path) -> Result<(), Error>
new_file_path as filename.
If new_file_path contains missing directories, they will be
created on the fly. Read moreSource§impl Debug for ContentString
impl Debug for ContentString
Source§impl Default for ContentString
Default is the empty string.
impl Default for ContentString
Default is the empty string.
Source§impl Display for ContentString
Delegates the printing to Display for ContentRef.
impl Display for ContentString
Delegates the printing to Display for ContentRef.
Source§impl Drop for ContentString
impl Drop for ContentString
Source§impl PartialEq for ContentString
impl PartialEq for ContentString
impl Eq for ContentString
Auto Trait Implementations§
impl Freeze for ContentString
impl RefUnwindSafe for ContentString
impl Send for ContentString
impl Sync for ContentString
impl Unpin for ContentString
impl UnwindSafe for ContentString
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
Source§impl<T> EncodedChars for T
impl<T> EncodedChars for T
Source§fn encoding(&self) -> *mut OnigEncodingTypeST
fn encoding(&self) -> *mut OnigEncodingTypeST
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more