YamlDocument

Struct YamlDocument 

Source
pub struct YamlDocument { /* private fields */ }
Expand description

A Unity YAML document containing one or more Unity objects

Implementations§

Source§

impl YamlDocument

Source

pub fn new() -> YamlDocument

Create a new empty YAML document

Source

pub fn load_yaml<P>( path: P, _preserve_types: bool, ) -> Result<YamlDocument, UnityAssetError>
where P: AsRef<Path>,

Load a Unity YAML file

§Arguments
  • path - Path to the YAML file to load
  • preserve_types - If true, try to preserve int/float types instead of converting all to strings
§Examples
use unity_asset_yaml::YamlDocument;

let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
Source

pub fn line_ending(&self) -> LineEnding

Get the line ending style

Source

pub fn set_line_ending(&mut self, newline: LineEnding)

Set the line ending style

Source

pub fn version(&self) -> Option<&str>

Get the YAML version

Source

pub fn yaml_metadata(&self) -> &HashMap<String, String>

Get the YAML metadata

Source

pub fn save(&self) -> Result<(), UnityAssetError>

Save document to its original file

This method saves the document back to the file it was loaded from. If the document was not loaded from a file, this will return an error.

§Examples
use unity_asset_yaml::YamlDocument;

let mut doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
// ... modify the document ...
doc.save()?;  // Save back to original file
Source

pub fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
where P: AsRef<Path>,

Save document to a specific file

This method serializes the document to Unity YAML format and saves it to the specified file path.

§Examples
use unity_asset_yaml::YamlDocument;

let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
doc.save_to("ProjectSettings_backup.asset")?;
Source

pub fn dump_yaml(&self) -> Result<String, UnityAssetError>

Get YAML content as string

This method serializes the document to Unity YAML format and returns it as a string without writing to a file.

§Examples
use unity_asset_yaml::YamlDocument;

let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
let yaml_string = doc.dump_yaml()?;
println!("{}", yaml_string);
Source

pub fn filter( &self, class_names: Option<&[&str]>, attributes: Option<&[&str]>, ) -> Vec<&UnityClass>

Filter entries by class names and/or attributes

This method provides advanced filtering capabilities similar to the Python reference library’s filter() method.

§Arguments
  • class_names - Optional list of class names to filter by
  • attributes - Optional list of attribute names that entries must have
§Examples
use unity_asset_yaml::YamlDocument;

let doc = YamlDocument::load_yaml("scene.unity", false)?;

// Find all GameObjects
let gameobjects = doc.filter(Some(&["GameObject"]), None);

// Find all objects with m_Enabled property
let enabled_objects = doc.filter(None, Some(&["m_Enabled"]));

// Find MonoBehaviours with m_Script property
let scripts = doc.filter(Some(&["MonoBehaviour"]), Some(&["m_Script"]));
Source

pub fn get( &self, class_name: Option<&str>, attributes: Option<&[&str]>, ) -> Result<&UnityClass, UnityAssetError>

Get a single entry by class name and/or attributes

This method returns the first entry that matches the criteria. Returns an error if no matching entry is found or if multiple entries match.

§Arguments
  • class_name - Optional class name to match
  • attributes - Optional list of attribute names that the entry must have
§Examples
use unity_asset_yaml::YamlDocument;

let doc = YamlDocument::load_yaml("scene.unity", false)?;

// Get the first GameObject
let gameobject = doc.get(Some("GameObject"), None)?;

// Get an object with specific attributes
let script = doc.get(Some("MonoBehaviour"), Some(&["m_Script", "m_Enabled"]))?;

Trait Implementations§

Source§

impl Debug for YamlDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for YamlDocument

Source§

fn default() -> YamlDocument

Returns the “default value” for a type. Read more
Source§

impl UnityDocument for YamlDocument

Source§

fn entry(&self) -> Option<&UnityClass>

Get the first entry (main object) in the document
Source§

fn entry_mut(&mut self) -> Option<&mut UnityClass>

Get a mutable reference to the first entry
Source§

fn entries(&self) -> &[UnityClass]

Get all entries in the document
Source§

fn entries_mut(&mut self) -> &mut Vec<UnityClass>

Get mutable access to all entries
Source§

fn add_entry(&mut self, entry: UnityClass)

Add a new Unity object to the document
Source§

fn file_path(&self) -> Option<&Path>

Get the file path this document was loaded from
Source§

fn save(&self) -> Result<(), UnityAssetError>

Save the document back to its original file
Source§

fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
where P: AsRef<Path>,

Save the document to a specific file
Source§

fn format(&self) -> DocumentFormat

Get the document format
Source§

fn filter_by_class(&self, class_name: &str) -> Vec<&UnityClass>

Filter entries by class name
Source§

fn filter_by_classes(&self, class_names: &[&str]) -> Vec<&UnityClass>

Filter entries by multiple class names
Source§

fn filter<F>(&self, predicate: F) -> Vec<&UnityClass>
where F: Fn(&UnityClass) -> bool,

Filter entries by a custom predicate
Source§

fn find_by_class_and_property( &self, class_name: &str, property: &str, ) -> Option<&UnityClass>

Find a single entry by class name and optional property filter
Source§

fn is_empty(&self) -> bool

Check if the document is empty
Source§

fn len(&self) -> usize

Get the number of entries in the document

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.