compris/resolve/common/
native.rs

1use super::super::{
2    super::{annotate::*, normal::*},
3    errors::*,
4    resolve::*,
5};
6
7use {
8    duplicate::*,
9    kutil::std::{error::*, immutable::*},
10};
11
12// Note that Strings will be cloned, so using ByteString is more efficient
13
14#[duplicate_item(
15  ResolvedT;
16  [isize];
17  [i64];
18  [i32];
19  [i16];
20  [i8];
21  [usize];
22  [u64];
23  [u32];
24  [u16];
25  [u8];
26  [f64];
27  [f32];
28  [bool];
29  [ByteString];
30  [String];
31  [Bytes];
32)]
33impl<AnnotatedT> Resolve<ResolvedT, AnnotatedT> for Variant<AnnotatedT>
34where
35    AnnotatedT: Annotated + Clone + Default,
36{
37    fn resolve_with_errors<ErrorReceiverT>(self, errors: &mut ErrorReceiverT) -> ResolveResult<ResolvedT, AnnotatedT>
38    where
39        ErrorReceiverT: ErrorReceiver<ResolveError<AnnotatedT>>,
40    {
41        let maybe_annotations = self.maybe_annotations();
42
43        Ok(match self.try_into() {
44            Ok(native) => Some(native),
45
46            Err(error) => {
47                errors.give(error.with_annotations_from(&maybe_annotations))?;
48                None
49            }
50        })
51    }
52}
53
54// Failed attempt at blanket generic:
55//
56// impl<'own, ResolvedT, ContextT, ErrorT> Resolve<ResolvedT, ContextT, ErrorT> for Value
57// where
58//     ContextT: ResolveContext,
59//     ErrorT: ResolveError,
60//     &'own Self: TryInto<ResolvedT, Error = IncompatibleValueTypeError>,
61// {
62//     fn resolve_for<ErrorReceiverT>(
63//         &self,
64//         _context: Option<&ContextT>,
65//         _ancestor: Option<&Value>,
66//         _errors: &mut ErrorReceiverT,
67//     ) -> ResolveResult<ResolvedT, ErrorT>
68//     where
69//         ErrorReceiverT: ErrorReceiver<ErrorT>,
70//     {
71//         Ok(match self.try_into() { // ouch, lifetimes!!!!!!!
72//             Ok(resolved) => Some(resolved),
73//             Err(_err) => {
74//                 //_errors.give(_err.with_citation_for(self, _context, _ancestor))?;
75//                 None
76//             }
77//         })
78//     }
79// }