Struct attheme::Attheme

source ·
pub struct Attheme {
    pub variables: Variables,
    pub wallpaper: Option<Wallpaper>,
}
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§

Creates an empty theme.

Examples
use attheme::Attheme;

let theme = Attheme::new();

assert!(theme.variables.is_empty());
assert_eq!(theme.wallpaper, None);

Creates an empty theme, with preallocation for capacity variables.

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.

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§

Adds all variables from other to self.

Notes

If other.wallpaper is None, it will fallback to self.wallpaper.

The resulting type after applying the + operator.
Performs the + operation. Read more

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.

The resulting type after applying the + operator.
Performs the + operation. Read more

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.

Performs the += operation. Read more

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.

Performs the += operation. Read more

Adds variables from &other if absent in &self.

Note that in this case, this works exactly as &other + &self.

The resulting type after applying the | operator.
Performs the | operation. Read more

Adds variables from other if absent in self.

Note that in this case, this works exactly as other + self.

The resulting type after applying the | operator.
Performs the | operation. Read more

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));
Performs the |= operation. Read more

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));
Performs the |= operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.