Skip to main content

Bookmark

Struct Bookmark 

Source
pub struct Bookmark {
    pub id: u32,
    pub name: String,
}
Expand description

A named bookmark (w:bookmarkStart’s w:name, CT_Bookmark), attached to one or more runs via Run.bookmarks to mark which run(s) fall within its range. Hyperlink::Internal’s anchor name is meant to match a bookmark’s name here for the resulting link to actually go anywhere in Word — not validated when writing (same best-effort posture as Paragraph.numbering_id referencing a declaration that may not exist).

Fields§

§id: u32

This bookmark’s id (w:bookmarkStart/w:bookmarkEnd’s w:id), pairing a start with its matching end — purely an internal wiring detail, never referenced from outside the document (unlike name, which is what Hyperlink::Internal’s anchor actually points to).

§name: String

This bookmark’s name (w:bookmarkStart’s w:name), what Hyperlink::Internal(name) refers to.

Implementations§

Source§

impl Bookmark

Source

pub fn new(id: u32, name: impl Into<String>) -> Bookmark

Creates a new bookmark with the given id and name. The id only needs to be unique among a paragraph’s currently-open bookmarks (mirroring comment_ids’s own uniqueness scope) — this crate does not track or validate uniqueness across the whole document.

Examples found in repository?
examples/docx_navigation_and_annotations.rs (line 39)
15fn main() -> office_toolkit::Result<()> {
16    let path = output_path("docx_navigation_and_annotations.docx");
17
18    let document =
19        Document::new()
20            .with_paragraph(heading(
21                "Hyperlinks: external, and internal to a bookmark",
22                false,
23            ))
24            .with_paragraph(
25                Paragraph::new()
26                    .with_run(Run::new("Visit the ").with_hyperlink(Hyperlink::External(
27                        "https://www.rust-lang.org".to_string(),
28                    )))
29                    .with_run(Run::new("or jump ").with_hyperlink(Hyperlink::External(
30                        "https://www.rust-lang.org".to_string(),
31                    )))
32                    .with_run(
33                        Run::new("down to the bookmark")
34                            .with_hyperlink(Hyperlink::Internal("Target".to_string())),
35                    ),
36            )
37            .with_paragraph(
38                Paragraph::new()
39                    .with_run(Run::new("Here is ").with_bookmark(Bookmark::new(0, "Target")))
40                    .with_run(
41                        Run::new("the bookmarked text.").with_bookmark(Bookmark::new(0, "Target")),
42                    ),
43            )
44            .with_paragraph(heading("Comments", true))
45            .with_paragraph(
46                Paragraph::new()
47                    .with_run(Run::new("This sentence "))
48                    .with_run(Run::new("needs a second look").with_comment(0))
49                    .with_run(Run::new(" before it ships.")),
50            )
51            .with_comment(
52                Comment::with_text(0, "Please double-check this claim.")
53                    .with_author("Reviewer")
54                    .with_initials("RV"),
55            )
56            .with_paragraph(heading("Footnotes and endnotes", true))
57            .with_paragraph(
58                Paragraph::with_text("A claim that needs a footnote")
59                    .with_run(Run::with_note_reference(NoteReference::Footnote(1)))
60                    .with_run(Run::new(", and another that needs an endnote"))
61                    .with_run(Run::with_note_reference(NoteReference::Endnote(1))),
62            )
63            .with_footnote(Note::footnote_with_text(
64                1,
65                "The footnote's own explanatory text.",
66            ))
67            .with_endnote(Note::endnote_with_text(
68                1,
69                "The endnote's own explanatory text.",
70            ))
71            .with_paragraph(heading("A structured document tag (content control)", true))
72            .with_paragraph(Paragraph::with_text("Before the content control:"))
73            .with_structured_document_tag(
74                StructuredDocumentTag::new()
75                    .with_id(42)
76                    .with_tag("CustomerName")
77                    .with_alias("Customer name")
78                    .with_paragraph(Paragraph::with_text("Acme Corp.")),
79            );
80
81    document.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}

Trait Implementations§

Source§

impl Clone for Bookmark

Source§

fn clone(&self) -> Bookmark

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bookmark

Source§

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

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

impl Eq for Bookmark

Source§

impl PartialEq for Bookmark

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Bookmark

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.