[][src]Struct hashtag::Hashtag

pub struct Hashtag {
    pub text: String,
    pub start: usize,
    pub end: usize,
}

A hashtag found in some text. See documentation of top level module for more info.

Fields

text: String

The text of the hashtag. If hashtag is "#rust" the text will be "rust".

assert_eq!(
    Hashtag::parse("#rust").get(0).unwrap().text,
    "rust".to_string()
);
start: usize

The starting index of the hashtag. This includes the # character. This makes it easier to highlight the hashtags later. If the full text we're parsing is "#rust" then start will be 0.

assert_eq!(
    Hashtag::parse("#rust").get(0).unwrap().start,
    0
);
end: usize

The ending index of the hashtag, inclusive. If the full text we're parsing is "#rust" then end will be 4.

assert_eq!(
    Hashtag::parse("#rust").get(0).unwrap().end,
    4
);

Methods

impl Hashtag[src]

pub fn parse(text: &str) -> Vec<Self>[src]

Parse a string and return a vector of the hashtags.

pub fn to_json(&self) -> String[src]

Convert a Hashtag into JSON using serde_json.

At Tonsser we use this crate from our Rails API with helix and because helix only supports passing strings back and forth we serialize the data as JSON and deserialize it in Ruby land.

Trait Implementations

impl PartialEq<Hashtag> for Hashtag[src]

impl Eq for Hashtag[src]

impl Debug for Hashtag[src]

impl Serialize for Hashtag[src]

impl<'de> Deserialize<'de> for Hashtag[src]

Auto Trait Implementations

impl Send for Hashtag

impl Sync for Hashtag

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]