pub struct YamlDocument { /* private fields */ }
Expand description
A Unity YAML document containing one or more Unity objects
Implementations§
Source§impl YamlDocument
impl YamlDocument
Sourcepub fn new() -> YamlDocument
pub fn new() -> YamlDocument
Create a new empty YAML document
Sourcepub fn load_yaml<P>(
path: P,
_preserve_types: bool,
) -> Result<YamlDocument, UnityAssetError>
pub fn load_yaml<P>( path: P, _preserve_types: bool, ) -> Result<YamlDocument, UnityAssetError>
Sourcepub fn line_ending(&self) -> LineEnding
pub fn line_ending(&self) -> LineEnding
Get the line ending style
Sourcepub fn set_line_ending(&mut self, newline: LineEnding)
pub fn set_line_ending(&mut self, newline: LineEnding)
Set the line ending style
Sourcepub fn yaml_metadata(&self) -> &HashMap<String, String>
pub fn yaml_metadata(&self) -> &HashMap<String, String>
Get the YAML metadata
Sourcepub fn save(&self) -> Result<(), UnityAssetError>
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
Sourcepub fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
pub fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
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")?;
Sourcepub fn dump_yaml(&self) -> Result<String, UnityAssetError>
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);
Sourcepub fn filter(
&self,
class_names: Option<&[&str]>,
attributes: Option<&[&str]>,
) -> Vec<&UnityClass>
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 byattributes
- 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"]));
Sourcepub fn get(
&self,
class_name: Option<&str>,
attributes: Option<&[&str]>,
) -> Result<&UnityClass, UnityAssetError>
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 matchattributes
- 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
impl Debug for YamlDocument
Source§impl Default for YamlDocument
impl Default for YamlDocument
Source§fn default() -> YamlDocument
fn default() -> YamlDocument
Source§impl UnityDocument for YamlDocument
impl UnityDocument for YamlDocument
Source§fn entry(&self) -> Option<&UnityClass>
fn entry(&self) -> Option<&UnityClass>
Source§fn entry_mut(&mut self) -> Option<&mut UnityClass>
fn entry_mut(&mut self) -> Option<&mut UnityClass>
Source§fn entries(&self) -> &[UnityClass]
fn entries(&self) -> &[UnityClass]
Source§fn entries_mut(&mut self) -> &mut Vec<UnityClass>
fn entries_mut(&mut self) -> &mut Vec<UnityClass>
Source§fn add_entry(&mut self, entry: UnityClass)
fn add_entry(&mut self, entry: UnityClass)
Source§fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
fn save_to<P>(&self, path: P) -> Result<(), UnityAssetError>
Source§fn format(&self) -> DocumentFormat
fn format(&self) -> DocumentFormat
Source§fn filter_by_class(&self, class_name: &str) -> Vec<&UnityClass>
fn filter_by_class(&self, class_name: &str) -> Vec<&UnityClass>
Source§fn filter_by_classes(&self, class_names: &[&str]) -> Vec<&UnityClass>
fn filter_by_classes(&self, class_names: &[&str]) -> Vec<&UnityClass>
Source§fn filter<F>(&self, predicate: F) -> Vec<&UnityClass>
fn filter<F>(&self, predicate: F) -> Vec<&UnityClass>
Source§fn find_by_class_and_property(
&self,
class_name: &str,
property: &str,
) -> Option<&UnityClass>
fn find_by_class_and_property( &self, class_name: &str, property: &str, ) -> Option<&UnityClass>
Auto Trait Implementations§
impl Freeze for YamlDocument
impl RefUnwindSafe for YamlDocument
impl Send for YamlDocument
impl Sync for YamlDocument
impl Unpin for YamlDocument
impl UnwindSafe for YamlDocument
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.