pub struct Reader<'a> { /* private fields */ }Expand description
Main struct for reading .blend files.
This struct is created by the read function.
§Examples
use blend_rs::blend::{read, Reader, ReadError};
let blend_data = std::fs::read("examples/example-3.2.blend")
.expect("file 'examples/example-3.2.blend' should exist and be readable");
let reader: Result<Reader, ReadError> = read(&blend_data);Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn iter<S>(&self) -> Result<StructIter<'_, S>, ReadError>where
S: 'a + GeneratedBlendStruct,
pub fn iter<S>(&self) -> Result<StructIter<'_, S>, ReadError>where
S: 'a + GeneratedBlendStruct,
Returns an iterator over all structs of the specified type.
§Errors
- Fails with a
VersionMismatchError, if theGeneratedBlendStructused to read is generated for a different version than the Blender data actually has. - Fails with a
PointerSizeMismatchError, if the size of addresses (32bit, 64bit) differs from the address size found in the Blender data. - Fails with a
EndiannessMismatchError, if theEndianness(little, big) differs from theEndiannessfound in the Blender data.
§Examples
use blend_rs::blend::{read, StructIter};
use blend_rs::blender3_2::Mesh;
let blend_data = std::fs::read("examples/example-3.2.blend")
.expect("file 'examples/example-3.2.blend' to be readable");
let reader = read(&blend_data)
.expect("Blender file should be parsable");
let meshes: StructIter<Mesh> = reader.iter::<Mesh>()
.expect("Blender file should contains Meshes");Sourcepub fn deref<P, S>(&self, pointer: &P) -> Result<StructIter<'_, S>, ReadError>
pub fn deref<P, S>(&self, pointer: &P) -> Result<StructIter<'_, S>, ReadError>
Dereferences the specified PointerLike and returns an iterator over the structs.
§Errors
- Fails with a
VersionMismatchError, if theGeneratedBlendStructused to read is generated for a different version than the Blender data actually has. - Fails with a
PointerSizeMismatchError, if the size of addresses (32bit, 64bit) differs from the address size found in the Blender data. - Fails with a
EndiannessMismatchError, if theEndianness(little, big) differs from theEndiannessfound in the Blender data. - Fails with a
InvalidPointerAddressError, if the address of the specifiedPointerLikeis invalid. - Fails with a
NullPointerError, if the address of the specifiedPointerLikeis zero. - Fails with a
InvalidPointerTypeError, if the generic target-type of thePointerLikediffers from the type actually found at the address in the Blender data.
§Examples
use blend_rs::blend::{read, PointerLike, NameLike, StructIter};
use blend_rs::blender3_2::{Mesh, MLoop, MPoly};
let blend_data = std::fs::read("examples/example-3.2.blend")
.expect("file 'examples/example-3.2.blend' should exist and be readable");
let reader = read(&blend_data)
.expect("Blender file should be parsable");
let mesh: &Mesh = reader.iter::<Mesh>()
.expect("Blender file should contains Meshes")
.find(|mesh| mesh.id.name.to_name_str_unchecked() == "Cube")
.expect("Blender file should contain a Mesh with name 'Cube'");
let polygons: StructIter<MPoly> = reader.deref(&mesh.mpoly)
.expect("an iterator over all polygons of the Mesh");Sourcepub fn deref_single<P, S>(&self, pointer: &P) -> Result<&'a S, ReadError>
pub fn deref_single<P, S>(&self, pointer: &P) -> Result<&'a S, ReadError>
Dereferences the specified PointerLike and returns the struct.
§Errors
- Fails with a
VersionMismatchError, if theGeneratedBlendStructused to read is generated for a different version than the Blender data actually has. - Fails with a
PointerSizeMismatchError, if the size of addresses (32bit, 64bit) differs from the address size found in the Blender data. - Fails with a
EndiannessMismatchError, if theEndianness(little, big) differs from theEndiannessfound in the Blender data. - Fails with a
InvalidPointerAddressError, if the address of the specifiedPointerLikeis invalid. - Fails with a
NullPointerError, if the address of the specifiedPointerLikeis zero. - Fails with a
InvalidPointerTypeError, if the generic target-type of thePointerLikediffers from the type actually found at the address in the Blender data.
§Examples
use blend_rs::blend::{read, PointerLike, NameLike};
use blend_rs::blender3_2::{Object, Mesh};
let blend_data = std::fs::read("examples/example-3.2.blend")
.expect("file 'examples/example-3.2.blend' should exist and be readable");
let reader = read(&blend_data)
.expect("Blender file should be parsable");
let cube: &Object = reader.iter::<Object>()
.expect("Blender file should contains Objects")
.find(|object| object.id.name.to_name_str_unchecked() == "Cube")
.expect("Blender file should contain an Object with name 'Cube'");
let mesh: &Mesh = reader.deref_single(&cube.data.as_instance_of::<Mesh>())
.expect("object 'Cube' should have a Mesh");Sourcepub fn deref_raw<P, S>(&self, pointer: &P) -> Result<Data<'a>, ReadError>
pub fn deref_raw<P, S>(&self, pointer: &P) -> Result<Data<'a>, ReadError>
Dereferences the specified PointerLike and returns a slice of the raw data.
§Errors
- Fails with a
VersionMismatchError, if theGeneratedBlendStructused to read is generated for a different version than the Blender data actually has. - Fails with a
PointerSizeMismatchError, if the size of addresses (32bit, 64bit) differs from the address size found in the Blender data. - Fails with a
EndiannessMismatchError, if theEndianness(little, big) differs from theEndiannessfound in the Blender data. - Fails with a
InvalidPointerAddressError, if the address of the specifiedPointerLikeis invalid. - Fails with a
NullPointerError, if the address of the specifiedPointerLikeis zero.
§Examples
use blend_rs::blend::{read, PointerLike, NameLike};
use blend_rs::blender3_2::{PackedFile};
let blend_data = std::fs::read("examples/example-3.2.blend")
.expect("file 'examples/example-3.2.blend' should exist and be readable");
let reader = read(&blend_data)
.expect("Blender data should be parsable");
let packed_file: &PackedFile = reader.iter::<PackedFile>()
.expect("an iterator over all PackedFiles")
.first()
.expect("at least one PackedFile");
let data = reader.deref_raw(&packed_file.data)
.expect("raw data of the PackedFile");Sourcepub fn deref_raw_range<P, S>(
&self,
pointer: &P,
range: Range<usize>,
) -> Result<Data<'a>, ReadError>
pub fn deref_raw_range<P, S>( &self, pointer: &P, range: Range<usize>, ) -> Result<Data<'a>, ReadError>
Dereferences the specified PointerLike and returns a sub-slice of the raw data.
§Errors
- Fails with a
VersionMismatchError, if theGeneratedBlendStructused to read is generated for a different version than the Blender data actually has. - Fails with a
PointerSizeMismatchError, if the size of addresses (32bit, 64bit) differs from the address size found in the Blender data. - Fails with a
EndiannessMismatchError, if theEndianness(little, big) differs from theEndiannessfound in the Blender data. - Fails with a
InvalidPointerAddressError, if the address of the specifiedPointerLikeis invalid. - Fails with a
NullPointerError, if the address of the specifiedPointerLikeis zero.
§Examples
use blend_rs::blend::{read, PointerLike, NameLike};
use blend_rs::blender3_2::{PackedFile};
let blend_data = std::fs::read("examples/example-3.2.blend")
.expect("file 'examples/example-3.2.blend' should exist and be readable");
let reader = read(&blend_data)
.expect("Blender file should be parsable");
let packed_file: &PackedFile = reader.iter::<PackedFile>()
.expect("Blender file should contains PackedFiles")
.first()
.expect("Blender file should contain at least one PackedFiles");
let magic_number = reader.deref_raw_range(&packed_file.data, 0..4 as usize)
.expect("a range of raw data of the PackedFile");
pub fn traverse_double_linked<PD, D, PT>(
&self,
pointer: &PD,
) -> Result<DoubleLinkedIter<'_, D, PT>, ReadError>where
PD: PointerLike<D>,
D: 'a + DoubleLinked<PT> + GeneratedBlendStruct + PointerTarget<D>,
PT: PointerLike<D>,
Auto Trait Implementations§
impl<'a> Freeze for Reader<'a>
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more