[−][src]Struct orgize::Headline
Represents a headline in Org
struct.
Each Org
has zero or more Headline
s.
Methods
impl Headline
[src]
pub fn new<'a>(ttl: Title<'a>, org: &mut Org<'a>) -> Headline
[src]
Creates a new detaced Headline.
pub fn level(self) -> usize
[src]
Returns the level of this headline.
pub fn headline_node(self) -> NodeId
[src]
Returns the ID of the headline element of this headline.
pub fn title_node(self) -> NodeId
[src]
Returns the ID of the title element of this headline.
pub fn section_node(self) -> Option<NodeId>
[src]
Returns the ID of the section element of this headline, or None
if it has no section.
pub fn title<'a: 'b, 'b>(self, org: &'b Org<'a>) -> &'b Title<'a>
[src]
Returns a reference to the title element of this headline.
pub fn title_mut<'a: 'b, 'b>(self, org: &'b mut Org<'a>) -> &'b mut Title<'a>
[src]
Returns a mutual reference to the title element of this headline.
Don't change the level and content of the &mut Titile
directly.
Alternatively, uses Headline::set_level
and Headline::set_title_content
.
let mut org = Org::parse("* h1"); let h1 = org.headlines().nth(0).unwrap(); h1.title_mut(&mut org).priority = Some('A'); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), "* [#A] h1\n", );
pub fn set_level(
&mut self,
lvl: usize,
org: &mut Org
) -> Result<(), ValidationError>
[src]
&mut self,
lvl: usize,
org: &mut Org
) -> Result<(), ValidationError>
Changes the level of this headline.
Returns an error if this headline is attached and the given new level dones't meet the requirements.
let mut org = Org::parse( r#" * h1 ****** h1_1 *** h1_2 ** h1_3 "#, ); let mut h1_2 = org.headlines().nth(2).unwrap(); // level must be greater than or equal to 2, and smaller than or equal to 6 assert!(h1_2.set_level(42, &mut org).is_err()); assert!(h1_2.set_level(5, &mut org).is_ok()); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * h1 ****** h1_1 ***** h1_2 ** h1_3 "#, ); // detached headline's levels can be changed freely let mut new_headline = Headline::new( Title { raw: "new".into(), ..Default::default() }, &mut org, ); new_headline.set_level(42, &mut org).unwrap();
pub fn set_title_content<'a, S>(self, content: S, org: &mut Org<'a>) where
S: Into<Cow<'a, str>>,
[src]
S: Into<Cow<'a, str>>,
Changes the title content of this headline.
let mut org = Org::parse( r#" * h1 ** h1_1 "#, ); let h1 = org.headlines().nth(0).unwrap(); let h1_1 = org.headlines().nth(1).unwrap(); h1.set_title_content("H1", &mut org); h1_1.set_title_content(String::from("*H1_1*"), &mut org); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * H1 ** *H1_1* "#, );
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 headline.
let mut org = Org::parse( r#" * h1 ** h1_1 s1_1 "#, ); let mut h1 = org.headlines().nth(0).unwrap(); let mut h1_1 = org.headlines().nth(1).unwrap(); h1.set_section_content("s1", &mut org); h1_1.set_section_content(String::from("*s1_1*"), &mut org); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * h1 s1 ** h1_1 *s1_1* "#, );
pub fn parent(self, org: &Org) -> Option<Headline>
[src]
Returns the parent of this headline, or None
if it is detached or attached to the document.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1 = org.headlines().nth(0).unwrap(); let h1_1 = org.headlines().nth(1).unwrap(); let h1_2_1 = org.headlines().nth(3).unwrap(); assert_eq!(h1_1.parent(&org).unwrap().title(&org).raw, "h1"); assert_eq!(h1_2_1.parent(&org).unwrap().title(&org).raw, "h1_2"); assert!(h1.parent(&org).is_none()); // detached headline have no parent assert!(Headline::new(Title::default(), &mut org).parent(&org).is_none());
pub fn children<'a>(self, org: &'a Org) -> impl Iterator<Item = Headline> + 'a
[src]
Returns an iterator of this headline's children.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1 = org.headlines().nth(0).unwrap(); let mut iter = h1.children(&org); assert_eq!(iter.next().unwrap().title(&org).raw, "h1_1"); assert_eq!(iter.next().unwrap().title(&org).raw, "h1_2"); assert_eq!(iter.next().unwrap().title(&org).raw, "h1_3"); assert!(iter.next().is_none());
pub fn first_child(self, org: &Org) -> Option<Headline>
[src]
Returns the first child of this headline, or None
if it has no child.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1_1 = org.headlines().nth(1).unwrap(); let h1_2 = org.headlines().nth(2).unwrap(); let h1_3 = org.headlines().nth(5).unwrap(); assert_eq!(h1_2.first_child(&org).unwrap().title(&org).raw, "h1_2_1"); assert!(h1_1.first_child(&org).is_none()); assert!(h1_3.first_child(&org).is_none());
pub fn last_child(self, org: &Org) -> Option<Headline>
[src]
Returns the last child of this headline, or None
if it has no child.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1_1 = org.headlines().nth(1).unwrap(); let h1_2 = org.headlines().nth(2).unwrap(); let h1_3 = org.headlines().nth(5).unwrap(); assert_eq!(h1_2.last_child(&org).unwrap().title(&org).raw, "h1_2_2"); assert!(h1_1.last_child(&org).is_none()); assert!(h1_3.last_child(&org).is_none());
pub fn previous(self, org: &Org) -> Option<Headline>
[src]
Returns the previous sibling of this headline, or None
if it is a first child.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1_1 = org.headlines().nth(1).unwrap(); let h1_2 = org.headlines().nth(2).unwrap(); let h1_2_1 = org.headlines().nth(3).unwrap(); assert_eq!(h1_2.previous(&org).unwrap().title(&org).raw, "h1_1"); assert!(h1_1.previous(&org).is_none()); assert!(h1_2_1.previous(&org).is_none());
pub fn next(self, org: &Org) -> Option<Headline>
[src]
Returns the next sibling of this headline, or None
if it is a last child.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1_2 = org.headlines().nth(2).unwrap(); let h1_2_2 = org.headlines().nth(4).unwrap(); let h1_3 = org.headlines().nth(5).unwrap(); assert_eq!(h1_2.next(&org).unwrap().title(&org).raw, "h1_3"); assert!(h1_3.next(&org).is_none()); assert!(h1_2_2.next(&org).is_none());
pub fn detach(self, org: &mut Org)
[src]
Detaches this headline from arena.
let mut org = Org::parse( r#" * h1 ** h1_1 ** h1_2 *** h1_2_1 *** h1_2_2 ** h1_3 "#, ); let h1_2 = org.headlines().nth(2).unwrap(); h1_2.detach(&mut org); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * h1 ** h1_1 ** h1_3 "#, );
pub fn is_detached(self, org: &Org) -> bool
[src]
Returns true
if this headline is detached.
pub fn append(self, hdl: Headline, org: &mut Org) -> Result<(), ValidationError>
[src]
Appends a new child to this headline.
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 ** h1_1 ***** h1_1_1 "#, ); let h1_1 = org.headlines().nth(1).unwrap(); let mut h1_1_2 = Headline::new( Title { raw: "h1_1_2".into(), ..Default::default() }, &mut org, ); // level must be greater than 2, and smaller than or equal to 5 h1_1_2.set_level(2, &mut org).unwrap(); assert!(h1_1.append(h1_1_2, &mut org).is_err()); h1_1_2.set_level(6, &mut org).unwrap(); assert!(h1_1.append(h1_1_2, &mut org).is_err()); h1_1_2.set_level(4, &mut org).unwrap(); assert!(h1_1.append(h1_1_2, &mut org).is_ok()); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * h1 ** h1_1 ***** h1_1_1 **** h1_1_2 "#, ); // cannot append an attached headline assert!(h1_1.append(h1_1_2, &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 headline.
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 ** h1_1 ***** h1_1_1 "#, ); let h1_1 = org.headlines().nth(1).unwrap(); let mut h1_1_2 = Headline::new( Title { raw: "h1_1_2".into(), ..Default::default() }, &mut org, ); // level must be greater than or equal to 5 h1_1_2.set_level(2, &mut org).unwrap(); assert!(h1_1.prepend(h1_1_2, &mut org).is_err()); h1_1_2.set_level(5, &mut org).unwrap(); assert!(h1_1.prepend(h1_1_2, &mut org).is_ok()); // cannot prepend an attached headline assert!(h1_1.prepend(h1_1_2, &mut org).is_err());
pub fn insert_before(
self,
hdl: Headline,
org: &mut Org
) -> Result<(), ValidationError>
[src]
self,
hdl: Headline,
org: &mut Org
) -> Result<(), ValidationError>
Inserts a new sibling before this headline.
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 ** h1_1 **** h1_1_1 *** h1_1_3 "#, ); let h1_1_3 = org.headlines().nth(3).unwrap(); let mut h1_1_2 = Headline::new( Title { raw: "h1_1_2".into(), ..Default::default() }, &mut org, ); // level must be greater than or equal to 3, but smaller than or equal to 4 h1_1_2.set_level(2, &mut org).unwrap(); assert!(h1_1_3.insert_before(h1_1_2, &mut org).is_err()); h1_1_2.set_level(5, &mut org).unwrap(); assert!(h1_1_3.insert_before(h1_1_2, &mut org).is_err()); h1_1_2.set_level(4, &mut org).unwrap(); assert!(h1_1_3.insert_before(h1_1_2, &mut org).is_ok()); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * h1 ** h1_1 **** h1_1_1 **** h1_1_2 *** h1_1_3 "#, ); // cannot insert an attached headline assert!(h1_1_3.insert_before(h1_1_2, &mut org).is_err());
pub fn insert_after(
self,
hdl: Headline,
org: &mut Org
) -> Result<(), ValidationError>
[src]
self,
hdl: Headline,
org: &mut Org
) -> Result<(), ValidationError>
Inserts a new sibling after this headline.
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 ** h1_1 **** h1_1_1 *** h1_1_3 "#, ); let h1_1_1 = org.headlines().nth(2).unwrap(); let mut h1_1_2 = Headline::new( Title { raw: "h1_1_2".into(), ..Default::default() }, &mut org, ); // level must be greater than or equal to 3, but smaller than or equal to 4 h1_1_2.set_level(2, &mut org).unwrap(); assert!(h1_1_1.insert_after(h1_1_2, &mut org).is_err()); h1_1_2.set_level(5, &mut org).unwrap(); assert!(h1_1_1.insert_after(h1_1_2, &mut org).is_err()); h1_1_2.set_level(4, &mut org).unwrap(); assert!(h1_1_1.insert_after(h1_1_2, &mut org).is_ok()); let mut writer = Vec::new(); org.org(&mut writer).unwrap(); assert_eq!( String::from_utf8(writer).unwrap(), r#" * h1 ** h1_1 **** h1_1_1 **** h1_1_2 *** h1_1_3 "#, ); // cannot insert an attached headline assert!(h1_1_1.insert_after(h1_1_2, &mut org).is_err());
Trait Implementations
Auto Trait Implementations
impl Send for Headline
impl Sync for Headline
impl Unpin for Headline
impl UnwindSafe for Headline
impl RefUnwindSafe for Headline
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,