Debian Codegraph @

src/result.rs

raw symbols SCIP
1 /*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9 //! Decoding results for images
10 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#;
11
12 /// A simple enum that can hold decode
13 /// results of most images
14 #[non_exhaustive]
15 pub enum DecodingResultrust-analyzer cargo zune-core 0.5.1 result/DecodingResult# {
16 U8rust-analyzer cargo zune-core 0.5.1 result/DecodingResult#U8#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>),
17 U16rust-analyzer cargo zune-core 0.5.1 result/DecodingResult#U16#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16>),
18 F32rust-analyzer cargo zune-core 0.5.1 result/DecodingResult#F32#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<f32>)
19 }
20
21 impl DecodingResultrust-analyzer cargo zune-core 0.5.1 result/DecodingResult# {
22 /// Return the contents if the enum stores `Vec<u8>` or otherwise
23 /// return `None`.
24 ///
25 /// Useful for de-sugaring the result of a decoding operation
26 /// into raw bytes
27 ///
28 /// # Example
29 /// ```
30 /// use zune_core::result::DecodingResult;
31 /// let data = DecodingResult::U8(vec![0;100]);
32 /// // we know this won't fail because we created it with u8
33 /// assert!(data.u8().is_some());
34 ///
35 /// let data = DecodingResult::U16(vec![0;100]);
36 /// // it should now return nothing since the type is u18
37 /// assert!(data.u8().is_none());
38 ///
39 /// ```
40 pub fn u8rust-analyzer cargo zune-core 0.5.1 result/impl#[DecodingResult]u8().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> {
41 match self {
42 DecodingResultrust-analyzer cargo zune-core 0.5.1 result/DecodingResult#::U8rust-analyzer cargo zune-core 0.5.1 result/DecodingResult#U8#(data) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(data),
43 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
44 }
45 }
46
47 /// Return the contents if the enum stores `Vec<u16>` or otherwise
48 /// return `None`.
49 ///
50 /// Useful for de-sugaring the result of a decoding operation
51 /// into raw bytes
52 ///
53 /// # Example
54 /// ```
55 /// use zune_core::result::DecodingResult;
56 /// let data = DecodingResult::U8(vec![0;100]);
57 /// // we know this will fail because we created it with u16
58 /// assert!(data.u16().is_none());
59 ///
60 ///
61 /// let data = DecodingResult::U16(vec![0;100]);
62 /// // it should now return something since the type is u16
63 /// assert!(data.u16().is_some());
64 ///
65 /// ```
66 pub fn u16rust-analyzer cargo zune-core 0.5.1 result/impl#[DecodingResult]u16().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16>> {
67 match self {
68 DecodingResultrust-analyzer cargo zune-core 0.5.1 result/DecodingResult#::U16rust-analyzer cargo zune-core 0.5.1 result/DecodingResult#U16#(data) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(data),
69 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
70 }
71 }
72 }