pddl/types/
objects.rs

1//! Contains the [`Objects`] type.
2
3use crate::types::{Name, Typed, TypedNames};
4use std::ops::Deref;
5
6/// A list of objects.
7///
8/// ## Usage
9/// Used by [`Problem`](crate::Problem).
10#[derive(Debug, Clone, Eq, PartialEq, Default)]
11pub struct Objects(TypedNames);
12
13impl Objects {
14    // TODO: Convert to const again that takes `TypedNames` directly.
15    pub fn new<I: IntoIterator<Item = Typed<Name>>>(objects: I) -> Self {
16        Self(objects.into_iter().collect())
17    }
18
19    pub fn values(&self) -> &TypedNames {
20        &self.0
21    }
22}
23
24impl From<TypedNames> for Objects {
25    fn from(value: TypedNames) -> Self {
26        Self(value)
27    }
28}
29
30impl FromIterator<Typed<Name>> for Objects {
31    fn from_iter<T: IntoIterator<Item = Typed<Name>>>(iter: T) -> Self {
32        Objects::new(TypedNames::from_iter(iter))
33    }
34}
35
36impl Deref for Objects {
37    type Target = TypedNames;
38
39    #[inline(always)]
40    fn deref(&self) -> &Self::Target {
41        &self.0
42    }
43}