dusk_cdf/decoder/
context.rs1use crate::Config;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct DecoderContext<'a> {
6 config: &'a Config,
7 source_names: &'a [String],
8 source_contents: &'a [String],
9}
10
11impl<'a> DecoderContext<'a> {
12 pub(crate) const BASE: Self = Self {
13 config: &Config::DEFAULT,
14 source_names: &[],
15 source_contents: &[],
16 };
17
18 pub(crate) const fn new(
19 config: &'a Config,
20 source_names: &'a [String],
21 source_contents: &'a [String],
22 ) -> Self {
23 Self {
24 config,
25 source_names,
26 source_contents,
27 }
28 }
29
30 pub const fn config(&self) -> &Config {
32 self.config
33 }
34
35 pub fn fetch_name(&self, id: usize) -> Option<&'a str> {
37 self.source_names.get(id).map(|s| s.as_str())
38 }
39
40 pub fn fetch_contents(&self, id: usize) -> Option<&'a str> {
42 self.source_contents.get(id).map(|s| s.as_str())
43 }
44}