pub struct PackageMeta { /* private fields */ }
Expand description
Metadata for the ScriptPackage.
You cannot instantiate this object manually; it is created automatically by the Script Engine for each exported Script Package per crate. However, you can obtain a static reference to the PackageMeta in several ways. For instance, you can get it from the ScriptPackage::meta function of the exported package struct. You can also manually find the reference using the PackageMeta::of function.
use ad_astra::{
export,
runtime::{PackageMeta, ScriptPackage},
};
#[export(package)]
#[derive(Default)]
struct Package;
let package_meta = Package::meta();
let same_package =
PackageMeta::of(package_meta.name(), &format!("={}", package_meta.version())).unwrap();
assert_eq!(package_meta, same_package);
You can use this reference to instantiate script modules or to run the LSP server.
The alternative Debug implementation for the package lists all script
modules currently associated with this Script Package. The alternative
Display implementation prints the canonical name of the package’s crate:
<package_name>@<package_version>
.
Implementations§
Source§impl PackageMeta
impl PackageMeta
Sourcepub fn of(name: &str, version: &str) -> Option<&'static Self>
pub fn of(name: &str, version: &str) -> Option<&'static Self>
Looks up the PackageMeta
by the package’s crate name
and version
.
The name
should match the exact crate name specified in the crate’s
Cargo.toml
configuration.
The version
specifies the crate version requirement. There can be
multiple crates with the same name but different versions in the crate
dependency graph. The format of the version
string is the same as used
in the [dependencies]
section of Cargo.toml
. For example, you can
specify the version as 3.0
to match the latest minor version, or use
the equality sign =2.1.5
to match a specific version exactly.
The function returns None if there are no crates with the specified name and version requirements or if the crates do not have an exported Script Package.
Sourcepub fn origin(&self) -> &'static RustOrigin
pub fn origin(&self) -> &'static RustOrigin
Returns the Rust source code location that points to where the package type was declared.
Sourcepub fn name(&self) -> &'static str
pub fn name(&self) -> &'static str
Returns the name of the crate for this package, as specified in the
crate’s Cargo.toml
.
Sourcepub fn version(&self) -> &'static str
pub fn version(&self) -> &'static str
Returns the version of the crate for this package, as specified in the
crate’s Cargo.toml
.
Sourcepub fn doc(&self) -> Option<&'static str>
pub fn doc(&self) -> Option<&'static str>
Returns the documentation URL of the crate for this package, as
specified in the crate’s Cargo.toml
.
Sourcepub fn ty(&self) -> &'static TypeMeta
pub fn ty(&self) -> &'static TypeMeta
Returns the type metadata of the Rust struct that has been exported as a ScriptPackage.
Sourcepub fn instance(&self) -> Cell
pub fn instance(&self) -> Cell
Returns a smart pointer to the instance of the Rust struct that represents the ScriptPackage.
The Script Engine automatically instantiates each package struct type during initialization, using the Default constructor of the Rust struct.
Through this instance, you can access the exported fields and methods of the struct. The crate’s exported global functions and statics are also available as components of this type. Additionally, dependency crates (that have exported ScriptPackage) become components of this instance.
The script code can access this instance using the crate
script
keyword or by referencing dependent crates
(my_crate.dep_crate
or crate.dep_crate
).
Trait Implementations§
Source§impl Debug for PackageMeta
impl Debug for PackageMeta
Source§impl Display for PackageMeta
impl Display for PackageMeta
Source§impl Hash for PackageMeta
impl Hash for PackageMeta
Source§impl Ord for PackageMeta
impl Ord for PackageMeta
Source§impl PartialEq for PackageMeta
impl PartialEq for PackageMeta
Source§impl PartialOrd for PackageMeta
impl PartialOrd for PackageMeta
impl Eq for PackageMeta
Auto Trait Implementations§
impl !Freeze for PackageMeta
impl !RefUnwindSafe for PackageMeta
impl Send for PackageMeta
impl Sync for PackageMeta
impl Unpin for PackageMeta
impl !UnwindSafe for PackageMeta
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> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more