[−][src]Struct orgize::Document
Represents the document in Org
struct.
Each Org
struct only has one Document
.
Methods
impl Document
[src]
pub fn section_node(self) -> Option<NodeId>
[src]
Returns the ID of the section element of this document,
or None
if it has no section.
pub fn children<'a>(self, org: &'a Org) -> impl Iterator<Item = Headline> + 'a
[src]
Returns an iterator of this document's children.
let mut org = Org::parse( r#" ** h1 ** h2 *** h2_1 *** h2_2 ** h3 "#, ); let d = org.document(); let mut iter = d.children(&org); assert_eq!(iter.next().unwrap().title(&org).raw, "h1"); assert_eq!(iter.next().unwrap().title(&org).raw, "h2"); assert_eq!(iter.next().unwrap().title(&org).raw, "h3"); assert!(iter.next().is_none());
pub fn first_child(self, org: &Org) -> Option<Headline>
[src]
Returns the first child of this document, or None
if it has no child.
let mut org = Org::parse( r#" ** h1 ** h2 *** h2_1 *** h2_2 ** h3 "#, ); let d = org.document(); assert_eq!(d.first_child(&org).unwrap().title(&org).raw, "h1");
let org = Org::new(); assert!(org.document().first_child(&org).is_none());
pub fn last_child(self, org: &Org) -> Option<Headline>
[src]
Returns the last child of this document, or None
if it has no child.
let mut org = Org::parse( r#" ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let d = org.document(); assert_eq!(d.last_child(&org).unwrap().title(&org).raw, "h1_3");
let org = Org::new(); assert!(org.document().last_child(&org).is_none());
pub fn set_section_content<'a, S>(&mut self, content: S, org: &mut Org<'a>) where
S: Into<Cow<'a, str>>,
[src]
S: Into<Cow<'a, str>>,
Changes the section content of this document.
let mut org = Org::parse( r#" ** h1_1 ** h1_2 "#, ); let mut d = org.document(); d.set_section_content("s", &mut org); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" s ** h1_1 ** h1_2 "#, );
pub fn append(self, hdl: Headline, org: &mut Org) -> Result<(), ValidationError>
[src]
Appends a new child to this document.
Returns an error if the given new child was already attached, or the given new child didn't meet the requirements.
let mut org = Org::parse( r#" ***** h1 **** h2 *** h3 "#, ); let d = org.document(); let mut h4 = Headline::new( Title { raw: "h4".into(), ..Default::default() }, &mut org, ); // level must be smaller than or equal to 3 h4.set_level(4, &mut org).unwrap(); assert!(d.append(h4, &mut org).is_err()); h4.set_level(2, &mut org).unwrap(); assert!(d.append(h4, &mut org).is_ok()); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" ***** h1 **** h2 *** h3 ** h4 "#, ); // cannot append an attached headline assert!(d.append(h4, &mut org).is_err());
pub fn prepend(
self,
hdl: Headline,
org: &mut Org
) -> Result<(), ValidationError>
[src]
self,
hdl: Headline,
org: &mut Org
) -> Result<(), ValidationError>
Prepends a new child to this document.
Returns an error if the given new child was already attached, or the given new child didn't meet the requirements.
let mut org = Org::parse( r#" ** h2 ** h3 "#, ); let d = org.document(); let mut h1 = Headline::new( Title { raw: "h1".into(), ..Default::default() }, &mut org, ); // level must be greater than 2 h1.set_level(1, &mut org).unwrap(); assert!(d.prepend(h1, &mut org).is_err()); h1.set_level(4, &mut org).unwrap(); assert!(d.prepend(h1, &mut org).is_ok()); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" **** h1 ** h2 ** h3 "#, ); // cannot prepend an attached headline assert!(d.prepend(h1, &mut org).is_err());
Trait Implementations
Auto Trait Implementations
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
impl RefUnwindSafe for Document
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,