diff --git a/donet/src/main.rs b/donet/src/main.rs index 8e34bb2..9e1144f 100644 --- a/donet/src/main.rs +++ b/donet/src/main.rs @@ -104,7 +104,7 @@ fn main() -> std::io::Result<()> { if want_dc_check { if let Some(dc_file) = dc_check_file { - let dc_read: DCReadResult = read_dc_files(vec![dc_file.to_string()]); + let dc_read: DCReadResult = read_dc_files(vec![dc_file.to_owned()]); if let Ok(mut dc_file) = dc_read { info!("No issues found. DC File Hash: {}", dc_file.get_pretty_hash()); diff --git a/libdonet/src/lib.rs b/libdonet/src/lib.rs index 9d32fff..2a8ecc2 100644 --- a/libdonet/src/lib.rs +++ b/libdonet/src/lib.rs @@ -75,6 +75,61 @@ cfg_if! { /// Easy to use interface for the DC file parser. Handles reading /// the DC files, instantiating the lexer and parser, and either /// returns the DCFile object or a Parse/File error. +/// +/// ## Example Usage +/// The following is an example of parsing a simple DC file string, +/// printing its DC hash in hexadecimal notation, and accessing +/// the elements of a defined Distributed Class: +/// ```rust +/// use libdonet::dcfile::DCFileInterface; +/// use libdonet::dclass::{DClass, DClassInterface}; +/// use libdonet::globals::DCReadResult; +/// use libdonet::read_dc_files; +/// +/// // All elements in a DC File object are thread-safe! +/// use std::sync::{Arc, Mutex, MutexGuard}; +/// +/// let dc_file: &str = "from game.ai import AnonymousContact/UD +/// from game.ai import LoginManager/AI +/// from game.world import DistributedWorld/AI +/// from game.avatar import DistributedAvatar/AI/OV +/// +/// dclass AnonymousContact { +/// login(string username, string password) clsend airecv; +/// }; +/// +/// dclass LoginManager { +/// login(channel client, string username, string password) airecv; +/// }; +/// +/// dclass DistributedWorld { +/// create_avatar(channel client) airecv; +/// }; +/// +/// dclass DistributedAvatar { +/// set_xyzh(int16 x, int16 y, int16 z, int16 h) broadcast required; +/// indicate_intent(int16 / 10, int16 / 10) ownsend airecv; +/// };"; +/// +/// let dc_read: DCReadResult = read_dc_files(vec![dc_file.into()]); +/// +/// if let Ok(mut dc_file) = dc_read { +/// println!("{}", dc_file.get_pretty_hash()); // Print the DC File Hash +/// +/// let avatar_class: Arc> = dc_file.get_dclass_by_id(3); +/// let mut locked_class: MutexGuard<'_, DClass> = avatar_class.lock().unwrap(); +/// +/// println!("{}", locked_class.get_name()); +/// } +/// ``` +/// +/// The output of the program would be the following: +/// ```txt +/// 0x01a5Fb0c +/// DistributedAvatar +/// ``` +///
+/// #[cfg(feature = "dcfile")] pub fn read_dc_files(file_paths: Vec) -> globals::DCReadResult { use crate::dclexer::Lexer;