Struct ContentString

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn borrow_owner<'_q>(&'_q self) -> &'_q String

Borrows owner.

Source

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.

Source

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.

Source

pub fn borrow_dependent<'_q>(&'_q self) -> &'_q ContentRef<'_q>

Borrows dependent.

Source

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.

Source§

fn as_ref(&self) -> &str

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

impl Content for ContentString

Add header() and body() implementation.

Source§

fn header(&self) -> &str

Cheap access to the note’s header.

Source§

fn body(&self) -> &str

Cheap access to the note’s body.

Source§

fn name(&self) -> &str

Returns the name as given at construction.

Source§

fn from_string(input: String, name: String) -> Self

Constructor that parses a Tp-Note document. A valid document is UTF-8 encoded and starts with an optional BOM (byte order mark) followed by ---. 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 more
Source§

fn open(path: &Path) -> Result<Self, Error>
where Self: Sized,

Reads the file at path and stores the content Content. Possible \r\n are replaced by \n. This trait has a default implementation, the empty content. Read more
Source§

fn from_string_with_cr(input: String, name: String) -> Self

Constructor that reads a structured document with a YAML header and body. All \r\n are converted to \n if there are any. If not no memory allocation occurs and the buffer remains untouched. Read more
Source§

fn from_html(input: String, name: String) -> Result<Self, InputStreamError>

Constructor that accepts and store HTML input in the body. If the HTML input does not start with <!DOCTYPE html...> it is automatically prepended. If the input starts with another DOCTYPE than HTMl, return InputStreamError::NonHtmlDoctype. Read more
Source§

fn save_as(&self, new_file_path: &Path) -> Result<(), Error>

Writes the note to disk with new_file_path as filename. If new_file_path contains missing directories, they will be created on the fly. Read more
Source§

fn as_str(&self) -> &str

Accesses the whole content with all ---. Contract: The content does not contain any \r\n. If your content contains \r\n use the from_string_with_cr() constructor. Possible BOM at the first position is not returned.
Source§

fn is_empty(&self) -> bool

True if the header and body is empty. Read more
Source§

fn split(content: &str) -> (&str, &str)

Helper function that splits the content into header and body. The header, if present, is trimmed (trim()), the body is kept as it is. Any BOM (byte order mark) at the beginning is ignored. Read more
Source§

impl Debug for ContentString

Source§

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

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

impl Default for ContentString

Default is the empty string.

Source§

fn default() -> Self

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

impl Display for ContentString

Delegates the printing to Display for ContentRef.

Source§

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

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

impl Drop for ContentString

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for ContentString

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ContentString

Auto Trait Implementations§

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> EncodedChars for T
where T: AsRef<str>,

Source§

fn start_ptr(&self) -> *const u8

Pointer to the start of the pattern Read more
Source§

fn limit_ptr(&self) -> *const u8

Pointer to the limit of the pattern buffer Read more
Source§

fn len(&self) -> usize

The length of this buffer
Source§

fn encoding(&self) -> *mut OnigEncodingTypeST

The encoding of the contents of the buffer
Source§

fn is_empty(&self) -> bool

Is the buffer empty?
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,