Struct renga_api_rs::Project
source · pub struct Project { /* private fields */ }Expand description
Represents active Renga project.
Provides methods to work with a Renga project. Can be obtained using crate::Application::project method.
By default, project is immutable. To achieve mutability, you must follow this steps:
- Create new transaction using Project::start_transaction method. Store it in a mutable variable.
- Do something with the project.
- Commit the transaction using ProjectTransaction::commit or discard it using ProjectTransaction::rollback methods.
For example:
use renga_api_rs as renga;
let mut app = renga::Application::new().unwrap();
let mut project = app.new_project().unwrap();
let mut transaction = project.start_transaction().unwrap();
// do something with the project
transaction.commit().unwrap();You can safely clone this struct and use it in multiple threads.
Implementations§
source§impl Project
impl Project
sourcepub fn new(parent_handle: Dispatch, handle: Dispatch) -> Result<Self>
pub fn new(parent_handle: Dispatch, handle: Dispatch) -> Result<Self>
Creates new instance of Project from native handles.
To get an instance of this structure without using native handles, use the crate::Application::new_project or crate::Application::project methods.
sourcepub fn path(&self) -> Result<Option<PathBuf>>
pub fn path(&self) -> Result<Option<PathBuf>>
Returns path to project save file or None if project was never saved.
See Project::save
sourcepub fn has_unsaved_changes(&self) -> Result<bool>
pub fn has_unsaved_changes(&self) -> Result<bool>
Returns `true`` if project has unsaved changes.
sourcepub fn close(&mut self, discard_changes: bool) -> Result<()>
pub fn close(&mut self, discard_changes: bool) -> Result<()>
Closes project.
If project has unsaved changes, you can discard them using discard_changes parameter.
sourcepub fn start_transaction(&mut self) -> Result<ProjectTransaction>
pub fn start_transaction(&mut self) -> Result<ProjectTransaction>
Creates new transaction.
See ProjectTransaction for more information.
sourcepub fn has_transaction(&self) -> Result<bool>
pub fn has_transaction(&self) -> Result<bool>
Returns true if project has an active transaction.
sourcepub fn category(&self, category: Category) -> Result<EntityCollection>
pub fn category(&self, category: Category) -> Result<EntityCollection>
Returns collection of entities of given category.
You can use this method to access entities inside categories.
For example, to get style template with name matching string Pump:
use renga_api_rs as renga;
use anyhow::Result;
fn style_template() -> Result<renga::Entity> {
let mut app = renga::Application::new()?;
let mut project = app.new_project()?;
let pump_style_template = project
.category(renga::Category::Equipment)?
.into_vec()?
.into_iter()
.find(|entity| entity.name == "Pump")
.unwrap();
Ok(pump_style_template)
}
let pump_style_template = style_template().unwrap();
assert_eq!(
pump_style_template.name,
"Pump"
);