Expand description
Represents contents of an .attheme file.
Fields§
§variables: Variables
An IndexMap
of variables of the theme.
wallpaper: Option<Wallpaper>
The image wallpaper of the theme.
Note that Telegram only recognizes .jpg
images, but the crate doesn’t
check that the wallpaper is actually a valid .jpg
. You should do it on
your own.
Implementations§
source§impl Attheme
impl Attheme
sourcepub fn new() -> Attheme
pub fn new() -> Attheme
Creates an empty theme.
Examples
use attheme::Attheme;
let theme = Attheme::new();
assert!(theme.variables.is_empty());
assert_eq!(theme.wallpaper, None);
sourcepub fn with_capacity(capacity: usize) -> Attheme
pub fn with_capacity(capacity: usize) -> Attheme
Creates an empty theme, with preallocation for capacity
variables.
sourcepub fn from_bytes(contents: &[u8]) -> Attheme
pub fn from_bytes(contents: &[u8]) -> Attheme
Parses .attheme contents passed as bytes.
Examples
use attheme::Attheme;
let contents = b"
checkbox=-1
checkboxCheck=#123456
divider=#40302010
WPS
Pretend it's Mona Lisa here
WPE
";
let theme = Attheme::from_bytes(contents);
assert_eq!(theme.variables["checkbox"], [0xff; 4]);
assert_eq!(theme.variables["checkboxCheck"], [0x12, 0x34, 0x56, 0xff]);
assert_eq!(theme.variables["divider"], [0x30, 0x20, 0x10, 0x40]);
assert_eq!(
theme.wallpaper,
Some(b"Pretend it's Mona Lisa here".to_vec()),
);
Notes
If Telegram can’t parse something, it will simply ignore it. This crate resembles this behavior.
Though Telegram only recognizes .jpg
images, the crate does not check
if the image is a valid .jpg
. You should do it on your own.
sourcepub fn to_bytes(&self, color_signature: ColorSignature) -> Vec<u8>
pub fn to_bytes(&self, color_signature: ColorSignature) -> Vec<u8>
Serializes the theme.
Examples
use attheme::*;
let mut theme = Attheme::new();
theme.variables.insert("divider".to_string(), [1, 2, 3, 4]);
theme.variables.insert("checkbox".to_string(), [0xff; 4]);
let expected_contents = b"divider=67174915
checkbox=-1
".to_vec();
assert_eq!(theme.to_bytes(ColorSignature::Int), expected_contents);
theme.wallpaper = Some(b"Pretend it's Mona Lisa here".to_vec());
let expected_contents = b"divider=#04010203
checkbox=#ffffffff
WPS
Pretend it's Mona Lisa here
WPE
".to_vec();
assert_eq!(theme.to_bytes(ColorSignature::Hex), expected_contents);
Trait Implementations§
source§impl<'a> Add<&'a Attheme> for &'a Attheme
impl<'a> Add<&'a Attheme> for &'a Attheme
Adds all variables from other
to self
.
Notes
If other.wallpaper
is None
, it will fallback to self.wallpaper
.
source§impl Add<Attheme> for Attheme
impl Add<Attheme> for Attheme
Adds all variables from other
to self
.
Example
use attheme::Attheme;
let mut first_theme = Attheme::new();
let mut second_theme = Attheme::new();
let wallpaper = b"Just pretending".to_vec();
first_theme.variables.insert("checkbox".to_string(), [0xff; 4]);
first_theme.wallpaper = Some(wallpaper.clone());
second_theme.variables.insert("checkbox".to_string(), [0x80; 4]);
second_theme.variables.insert("divider".to_string(), [0x40; 4]);
let third_theme = first_theme + second_theme;
assert_eq!(third_theme.variables["checkbox"], [0x80; 4]);
assert_eq!(third_theme.variables["divider"], [0x40; 4]);
assert_eq!(third_theme.wallpaper, Some(wallpaper));
Notes
If other.wallpaper
is None
, it will fallback to self.wallpaper
.
source§impl<'a> AddAssign<&'a Attheme> for Attheme
impl<'a> AddAssign<&'a Attheme> for Attheme
Adds all variables from the &other
theme to self
.
Example
use attheme::Attheme;
let mut first_theme = Attheme::new();
let mut second_theme = Attheme::new();
let wallpaper = b"Just pretending".to_vec();
first_theme.variables.insert("checkbox".to_string(), [0xff; 4]);
first_theme.wallpaper = Some(wallpaper.clone());
second_theme.variables.insert("checkbox".to_string(), [0x80; 4]);
second_theme.variables.insert("divider".to_string(), [0x40; 4]);
first_theme += &second_theme;
assert_eq!(
first_theme.variables["checkbox"],
second_theme.variables["checkbox"],
);
assert_eq!(
first_theme.variables["divider"],
second_theme.variables["divider"],
);
assert_eq!(first_theme.wallpaper, Some(wallpaper));
Notes
If other.wallpaper
is None
, the wallpaper won’t be removed.
source§fn add_assign(&mut self, other: &Attheme)
fn add_assign(&mut self, other: &Attheme)
+=
operation. Read moresource§impl AddAssign<Attheme> for Attheme
impl AddAssign<Attheme> for Attheme
Adds all variables from the other
theme to self
.
Example
use attheme::Attheme;
let mut first_theme = Attheme::new();
let mut second_theme = Attheme::new();
let wallpaper = b"Just pretending".to_vec();
first_theme.variables.insert("checkbox".to_string(), [0xff; 4]);
first_theme.wallpaper = Some(wallpaper.clone());
second_theme.variables.insert("checkbox".to_string(), [0x80; 4]);
second_theme.variables.insert("divider".to_string(), [0x40; 4]);
first_theme += second_theme;
assert_eq!(first_theme.variables["checkbox"], [0x80; 4]);
assert_eq!(first_theme.variables["divider"], [0x40; 4]);
assert_eq!(first_theme.wallpaper, Some(wallpaper));
Notes
If other.wallpaper
is None
, the wallpaper won’t be removed.
source§fn add_assign(&mut self, other: Attheme)
fn add_assign(&mut self, other: Attheme)
+=
operation. Read moresource§impl<'a> BitOr<&'a Attheme> for &'a Attheme
impl<'a> BitOr<&'a Attheme> for &'a Attheme
Adds variables from &other
if absent in &self
.
Note that in this case, this works exactly as &other + &self
.
source§impl BitOr<Attheme> for Attheme
impl BitOr<Attheme> for Attheme
Adds variables from other
if absent in self
.
Note that in this case, this works exactly as other + self
.
source§impl<'a> BitOrAssign<&'a Attheme> for Attheme
impl<'a> BitOrAssign<&'a Attheme> for Attheme
Similar to theme |= other
, but clones only when neccesary.
Example
use attheme::Attheme;
let mut first_theme = Attheme::new();
let mut second_theme = Attheme::new();
let wallpaper = b"Just pretending".to_vec();
first_theme.variables.insert("checkbox".to_string(), [0xff; 4]);
first_theme.wallpaper = Some(wallpaper.clone());
second_theme.variables.insert("checkbox".to_string(), [0x80; 4]);
second_theme.variables.insert("divider".to_string(), [0x40; 4]);
first_theme |= &second_theme;
assert_eq!(first_theme.variables["checkbox"], [0xff; 4]);
assert_eq!(
first_theme.variables["divider"],
second_theme.variables["divider"],
);
assert_eq!(first_theme.wallpaper, Some(wallpaper));
source§fn bitor_assign(&mut self, other: &'a Attheme)
fn bitor_assign(&mut self, other: &'a Attheme)
|=
operation. Read moresource§impl BitOrAssign<Attheme> for Attheme
impl BitOrAssign<Attheme> for Attheme
Adds variables from other
that are absent in self
.
Example
use attheme::Attheme;
let mut first_theme = Attheme::new();
let mut second_theme = Attheme::new();
let wallpaper = b"Just pretending".to_vec();
first_theme.variables.insert("checkbox".to_string(), [0xff; 4]);
first_theme.wallpaper = Some(wallpaper.clone());
second_theme.variables.insert("checkbox".to_string(), [0x80; 4]);
second_theme.variables.insert("divider".to_string(), [0x40; 4]);
first_theme |= second_theme;
assert_eq!(first_theme.variables["checkbox"], [0xff; 4]);
assert_eq!(first_theme.variables["divider"], [0x40; 4]);
assert_eq!(first_theme.wallpaper, Some(wallpaper));
source§fn bitor_assign(&mut self, other: Attheme)
fn bitor_assign(&mut self, other: Attheme)
|=
operation. Read more