pub struct Bodies<'a> { /* private fields */ }
Expand description
A collection of body paragraphs from a commit message.
This struct represents multiple body paragraphs that make up the content of a commit message.
§Examples
use mit_commit::{Bodies, Body, Subject};
let bodies: Vec<Body> = Vec::default();
assert_eq!(None, Bodies::from(bodies).first());
let bodies: Vec<Body> = vec![
Body::from("First"),
Body::from("Second"),
Body::from("Third"),
];
assert_eq!(Some(Body::from("First")), Bodies::from(bodies).first());
Implementations§
Source§impl Bodies<'_>
impl Bodies<'_>
Sourcepub fn first(&self) -> Option<Body<'_>>
pub fn first(&self) -> Option<Body<'_>>
Get the first Body
in this list of Bodies
§Arguments
self
- The Bodies collection to get the first element from
§Returns
The first Body in the list, or None if the list is empty
§Examples
use mit_commit::{Bodies, Body, Subject};
let bodies: Vec<Body> = Vec::default();
assert_eq!(None, Bodies::from(bodies).first());
let bodies: Vec<Body> = vec![
Body::from("First"),
Body::from("Second"),
Body::from("Third"),
];
assert_eq!(Some(Body::from("First")), Bodies::from(bodies).first());
Sourcepub fn iter(&self) -> Iter<'_, Body<'_>>
pub fn iter(&self) -> Iter<'_, Body<'_>>
Iterate over the Body
in the Bodies
§Arguments
self
- The Bodies collection to iterate over
§Returns
An iterator over the Body elements in the Bodies collection
§Examples
use mit_commit::{Bodies, Body};
let bodies = Bodies::from(vec![
Body::from("Body 1"),
Body::from("Body 2"),
Body::from("Body 3"),
]);
let mut iterator = bodies.iter();
assert_eq!(iterator.next(), Some(&Body::from("Body 1")));
assert_eq!(iterator.next(), Some(&Body::from("Body 2")));
assert_eq!(iterator.next(), Some(&Body::from("Body 3")));
assert_eq!(iterator.next(), None);
Trait Implementations§
Source§impl Display for Bodies<'_>
impl Display for Bodies<'_>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Render the Bodies
as text
§Arguments
self
- The Bodies collection to formatf
- The formatter to write the formatted string to
§Returns
A string representation of the Bodies with each Body separated by double newlines
§Examples
use mit_commit::{Bodies, Body};
let bodies = Bodies::from(vec![
Body::from("Body 1"),
Body::from("Body 2"),
Body::from("Body 3"),
]);
assert_eq!(format!("{}", bodies), "Body 1\n\nBody 2\n\nBody 3");
Source§impl From<Bodies<'_>> for String
impl From<Bodies<'_>> for String
Source§fn from(bodies: Bodies<'_>) -> Self
fn from(bodies: Bodies<'_>) -> Self
Convert a Bodies
collection to a String
§Arguments
bodies
- The Bodies collection to convert to a string
§Returns
A string representation of the Bodies with each Body separated by double newlines
§Examples
use mit_commit::{Bodies, Body};
let bodies = Bodies::from(vec![
Body::from("Body 1"),
Body::from("Body 2"),
Body::from("Body 3"),
]);
assert_eq!(String::from(bodies), "Body 1\n\nBody 2\n\nBody 3");
Source§impl<'a> From<Vec<Body<'a>>> for Bodies<'a>
impl<'a> From<Vec<Body<'a>>> for Bodies<'a>
Source§fn from(bodies: Vec<Body<'a>>) -> Self
fn from(bodies: Vec<Body<'a>>) -> Self
Combine a Vec
of Body
into Bodies
§Arguments
bodies
- A vector of Body objects to be combined into a Bodies collection
§Returns
A new Bodies instance containing all the provided Body objects
§Examples
use mit_commit::{Bodies, Body};
let bodies = Bodies::from(vec![
Body::from("Body 1"),
Body::from("Body 2"),
Body::from("Body 3"),
]);
let mut iterator = bodies.into_iter();
assert_eq!(iterator.next(), Some(Body::from("Body 1")));
assert_eq!(iterator.next(), Some(Body::from("Body 2")));
assert_eq!(iterator.next(), Some(Body::from("Body 3")));
assert_eq!(iterator.next(), None);
Source§impl<'a> From<Vec<Fragment<'a>>> for Bodies<'a>
impl<'a> From<Vec<Fragment<'a>>> for Bodies<'a>
Source§fn from(bodies: Vec<Fragment<'a>>) -> Self
fn from(bodies: Vec<Fragment<'a>>) -> Self
Convert a vector of Fragment
to Bodies
This extracts all Body fragments from the input, skipping the first one (which is typically the subject line) and any trailers at the end of the message.
§Arguments
bodies
- A vector of Fragment objects to extract Body fragments from
§Returns
A new Bodies instance containing only the Body fragments that are not the subject line and not trailers
§Examples
use mit_commit::{Bodies, Body, Fragment};
let fragments = vec![
Fragment::Body(Body::from("Subject Line")),
Fragment::Body(Body::default()),
Fragment::Body(Body::from("Some content in the body")),
Fragment::Body(Body::default()),
Fragment::Body(Body::from("Co-authored-by: Someone <someone@example.com>")),
];
let bodies = Bodies::from(fragments);
assert_eq!(
bodies,
Bodies::from(vec![
Body::default(),
Body::from("Some content in the body"),
])
);
Source§impl<'a> IntoIterator for &'a Bodies<'a>
impl<'a> IntoIterator for &'a Bodies<'a>
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Iterate over the Body
in the Bodies
§Arguments
self
- A reference to the Bodies collection to iterate over
§Returns
An iterator over references to the Body elements in the Bodies collection
§Examples
use std::borrow::Borrow;
use mit_commit::{Bodies, Body};
let bodies = Bodies::from(vec![
Body::from("Body 1"),
Body::from("Body 2"),
Body::from("Body 3"),
]);
let bodies_ref = bodies.borrow();
let mut iterator = bodies_ref.into_iter();
assert_eq!(iterator.next(), Some(&Body::from("Body 1")));
assert_eq!(iterator.next(), Some(&Body::from("Body 2")));
assert_eq!(iterator.next(), Some(&Body::from("Body 3")));
assert_eq!(iterator.next(), None);
Source§impl<'a> IntoIterator for Bodies<'a>
impl<'a> IntoIterator for Bodies<'a>
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Iterate over the Body
in the Bodies
§Arguments
self
- The Bodies collection to consume and iterate over
§Returns
An iterator that takes ownership of the Bodies collection
§Examples
use mit_commit::{Bodies, Body};
let bodies = Bodies::from(vec![
Body::from("Body 1"),
Body::from("Body 2"),
Body::from("Body 3"),
]);
let mut iterator = bodies.into_iter();
assert_eq!(iterator.next(), Some(Body::from("Body 1")));
assert_eq!(iterator.next(), Some(Body::from("Body 2")));
assert_eq!(iterator.next(), Some(Body::from("Body 3")));
assert_eq!(iterator.next(), None);