Struct PackageMeta

Source
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

Source

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.

Source

pub fn origin(&self) -> &'static RustOrigin

Returns the Rust source code location that points to where the package type was declared.

Source

pub fn name(&self) -> &'static str

Returns the name of the crate for this package, as specified in the crate’s Cargo.toml.

Source

pub fn version(&self) -> &'static str

Returns the version of the crate for this package, as specified in the crate’s Cargo.toml.

Source

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.

Source

pub fn ty(&self) -> &'static TypeMeta

Returns the type metadata of the Rust struct that has been exported as a ScriptPackage.

Source

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

Source§

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

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

impl Display for PackageMeta

Source§

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

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

impl Hash for PackageMeta

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for PackageMeta

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for PackageMeta

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PackageMeta

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for PackageMeta

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> ToCompactString for T
where T: Display,

Source§

fn to_compact_string(&self) -> CompactString

Converts the given value to a CompactString. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.