| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::one::property::PropertyType; |
| 3 |
use crate::onestore::object::Object; |
| 4 |
use crate::onestore::types::property::{PropertyId, PropertyValue}; |
| 5 |
|
| 6 |
pub(crate) struct References; |
| 7 |
|
| 8 |
impl References { |
| 9 |
pub(crate) fn get_predecessors<'a>( |
| 10 |
prop_type: PropertyType, |
| 11 |
object: &'a Object<'a>, |
| 12 |
) -> Result<impl Iterator<Item = &'a PropertyValue>> { |
| 13 |
let prop_index = object |
| 14 |
.props() |
| 15 |
.properties() |
| 16 |
.index(PropertyId::new(prop_type as u32)) |
| 17 |
.ok_or_else(|| { |
| 18 |
ErrorKind::MalformedOneNoteFileData( |
| 19 |
format!("no object offset for property {:?}", prop_type).into(), |
| 20 |
) |
| 21 |
})?; |
| 22 |
|
| 23 |
let predecessors = object |
| 24 |
.props() |
| 25 |
.properties() |
| 26 |
.values_with_index() |
| 27 |
.filter(move |(idx, _)| *idx < prop_index) |
| 28 |
.map(|(_, value)| value); |
| 29 |
|
| 30 |
Ok(predecessors) |
| 31 |
} |
| 32 |
} |