Debian Codegraph @

src/formats/gray_alpha.rs

raw symbols SCIP
1 use craterust-analyzer cargo rgb 0.8.53 crate/::formatsrust-analyzer cargo rgb 0.8.53 formats/::gray_arust-analyzer cargo rgb 0.8.53 formats/gray_a/::GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#;
2 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#};
3
4 #[repr(C)]
5 #[cfg_attr(feature = "unstable-experimental", deprecated(note = "renamed to GrayA"))]
6 #[cfg_attr(feature = "serde", derive(serderust-analyzer cargo serde 1.0.225 crate/::Serializerust-analyzer cargo serde_derive 1.0.225 Serialize:, serderust-analyzer cargo serde 1.0.225 crate/::Deserializerust-analyzer cargo serde_derive 1.0.225 Deserialize:))]
7 #[cfg_attr(feature = "defmt-03", derive(defmtrust-analyzer cargo defmt 0.3.100 crate/::Formatrust-analyzer cargo defmt-macros 1.0.1 Format:))]
8 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
9 /// A pixel for grayscale value + alpha components (rgb crate v0.8)
10 ///
11 /// Through a `Deref` hack it renames the fields from `.0` and `.1`
12 /// to `.v` (value) and `.a` (alpha)
13 #[allow(non_camel_case_types)]
14 pub struct GrayAlpha_v08rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#<T, A = T>(
15 /// Grayscale Component
16 ///
17 /// This field has been renamed to `.v`
18 #[deprecated(note = "Please use the .v field instaed (it's available through the magic of Deref to GrayA type)")]
19 pub T,
20 /// Alpha Component. This field has been renamed to `.a`.
21 #[deprecated(note = "Please use the .a field instead (it's available through the magic of Deref to GrayA type)")]
22 pub A,
23 );
24
25 impl<T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#> GrayAlpha_v08rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#<T> {
26 /// Reads the `.v` field
27 ///
28 /// Please use the `.v` field directly whenever possible. This function isn't necessary, and exists only to ease migration between major versions of the RGB crate.
29 #[allow(deprecated)]
30 pub fn valuerust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T>`]value().(self) -> T {
31 self.0rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#0.
32 }
33
34 /// Exposes the `.v` field for writing
35 ///
36 /// Please use the `.v` field directly whenever possible. This function isn't necessary, and exists only to ease migration between major versions of the RGB crate.
37 #[allow(deprecated)]
38 pub fn value_mutrust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T>`]value_mut().(&mut self) -> &mut T {
39 &mut self.0rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#0.
40 }
41 }
42
43 impl<T, A> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for GrayAlpha_v08rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#<T, A> {
44 type Targetrust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T, A>`][Deref]Target# = GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#<T, A>;
45
46 /// A trick that allows using `.v` and `.a` on the old `GrayAlpha` type.
47 fn derefrust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T, A>`][Deref]deref().(&self) -> &GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#<T, A> {
48 unsafe {
49 &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(self as *const Selfrust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T, A>`][Deref]).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().::<GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#::<T, A>>()
50 }
51 }
52 }
53
54 impl<T, A> DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for GrayAlpha_v08rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#<T, A> {
55 /// A trick that allows using `.v` and `.a` on the old `GrayAlpha` type.
56 fn deref_mutrust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T, A>`][DerefMut]deref_mut().(&mut self) -> &mut GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#<T, A> {
57 unsafe {
58 &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(self as *mut Selfrust-analyzer cargo rgb 0.8.53 formats/gray_alpha/impl#[`GrayAlpha_v08<T, A>`][DerefMut]).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#::<T, A>>()
59 }
60 }
61 }
62
63 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
64 #[allow(deprecated)]
65 fn swizzlerust-analyzer cargo rgb 0.8.53 formats/gray_alpha/swizzle().() {
66 let mut g = GrayAlpha_v08rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#(10u8, 20u8);
67 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(10, g.vrust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#v.);
68 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(20, g.arust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#a.);
69 g.arust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#a. = 7;
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(10, g.vrust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#v.);
71 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(7, g.1rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#1.);
72 }