Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

Represents a Gemini document.

Provides convenient methods for programatically creation of Gemini documents.

Implementations§

Source§

impl Document

Source

pub fn new() -> Self

Creates an empty Gemini Document.

§Examples
let document = kochab::Document::new();

assert_eq!(document.to_string(), "");
Source

pub fn add_blank_line(&mut self) -> &mut Self

Adds a blank line to the document.

§Examples
let mut document = kochab::Document::new();

document.add_blank_line();

assert_eq!(document.to_string(), "\n");
Source

pub fn add_text(&mut self, text: impl AsRef<str>) -> &mut Self

Adds plain text to the document.

This function allows adding multiple lines at once.

It inserts a whitespace at the beginning of a line if it starts with a character sequence that would make it a non-plain text line (e.g. link, heading etc).

§Examples
let mut document = kochab::Document::new();

document.add_text("hello\n* world!");

assert_eq!(document.to_string(), "hello\n * world!\n");

Adds a link to the document.

uris that fail to parse are substituted with ..

Consecutive newlines in label will be replaced with a single whitespace.

§Examples
let mut document = kochab::Document::new();

document.add_link("https://wikipedia.org", "Wiki\n\nWiki");

assert_eq!(document.to_string(), "=> https://wikipedia.org/ Wiki Wiki\n");

Adds a link to the document, but without a label.

See add_link for details.

§Examples
let mut document = kochab::Document::new();

document.add_link_without_label("https://wikipedia.org");

assert_eq!(document.to_string(), "=> https://wikipedia.org/\n");
Source

pub fn add_preformatted( &mut self, preformatted_text: impl AsRef<str>, ) -> &mut Self

Adds a block of preformatted text.

Lines that start with ``` will be prependend with a whitespace.

§Examples
let mut document = kochab::Document::new();

document.add_preformatted("a\n b\n  c");

assert_eq!(document.to_string(), "```\na\n b\n  c\n```\n");
Source

pub fn add_preformatted_with_alt( &mut self, alt: impl AsRef<str>, preformatted_text: impl AsRef<str>, ) -> &mut Self

Adds a block of preformatted text with an alt text.

Consecutive newlines in alt will be replaced with a single whitespace.

preformatted_text lines that start with ``` will be prependend with a whitespace.

§Examples
let mut document = kochab::Document::new();

document.add_preformatted_with_alt("rust", "fn main() {\n}\n");

assert_eq!(document.to_string(), "```rust\nfn main() {\n}\n```\n");
Source

pub fn add_heading( &mut self, level: HeadingLevel, text: impl Cowy<str>, ) -> &mut Self

Adds a heading.

Consecutive newlines in text will be replaced with a single whitespace.

§Examples
use kochab::document::HeadingLevel::H1;

let mut document = kochab::Document::new();

document.add_heading(H1, "Welcome!");

assert_eq!(document.to_string(), "# Welcome!\n");
Source

pub fn add_unordered_list_item(&mut self, text: impl AsRef<str>) -> &mut Self

Adds an unordered list item.

Consecutive newlines in text will be replaced with a single whitespace.

§Examples
let mut document = kochab::Document::new();

document.add_unordered_list_item("milk");
document.add_unordered_list_item("eggs");

assert_eq!(document.to_string(), "* milk\n* eggs\n");
Source

pub fn add_quote(&mut self, text: impl AsRef<str>) -> &mut Self

Adds a quote.

This function allows adding multiple quote lines at once.

§Examples
let mut document = kochab::Document::new();

document.add_quote("I think,\ntherefore I am");

assert_eq!(document.to_string(), "> I think,\n> therefore I am\n");

Trait Implementations§

Source§

impl Default for Document

Source§

fn default() -> Document

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

impl Display for Document

Source§

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

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

impl From<&Document> for Handler

Source§

fn from(doc: &Document) -> Self

Serve an unchanging response, shorthand for From

This document will be sent in response to any requests that arrive at this handler. As with all documents, this will be a successful response with a text/gemini MIME.

This will create a StaticHandler

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> 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> 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.