Skip to main content

twitter_text/
entity.rs

1// Copyright 2019 Robert Sayre
2// Licensed under the Apache License, Version 2.0
3// http://www.apache.org/licenses/LICENSE-2.0
4
5#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
6pub enum Type {
7    URL,
8    HASHTAG,
9    MENTION,
10    CASHTAG
11}
12
13#[derive(PartialEq, Eq, Hash, Clone, Debug)]
14pub struct Entity<'a> {
15    pub t: Type,
16    pub start: i32,
17    pub end: i32,
18    pub value: &'a str,
19    pub list_slug: &'a str,
20    pub display_url: &'a str,
21    pub expanded_url: &'a str
22}
23
24impl<'a> Entity<'a> {
25    pub fn get_type(&self) -> Type { self.t }
26    pub fn get_start(&self) -> i32 { self.start }
27    pub fn get_end(&self) -> i32 { self.end }
28    pub fn get_value(&self) -> &str { &self.value }
29    pub fn get_list_slug(&self) -> &'a str {
30        &self.list_slug
31    }
32    pub fn get_display_url(&self) -> &'a str {
33        &self.display_url
34    }
35    pub fn get_expanded_url(&self) -> &'a str {
36        &self.expanded_url
37    }
38
39    pub fn new(t: Type, value: &'a str, start: i32, end: i32) -> Entity<'a> {
40        Entity::new_list(t, value, "", start, end)
41    }
42
43    pub fn new_list(t: Type, value: &'a str, list_slug: &'a str, start: i32, end: i32) -> Entity<'a> {
44        Entity {
45            t, value, list_slug, start, end,
46            display_url: "",
47            expanded_url: ""
48        }
49    }
50}