Skip to content

Commit da16c6a

Browse files
committed
[Rust] Add Platform::get_type_library_by_name
1 parent 2271fcd commit da16c6a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

rust/src/platform.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ impl Platform {
173173
unsafe { TypeContainer::from_raw(type_container_ptr.unwrap()) }
174174
}
175175

176+
/// Get all the type libraries that have been registered with the name.
177+
///
178+
/// NOTE: This is a list because libraries can have `alternate_names`, use [`Platform::get_type_library_by_name`]
179+
/// if you want to get _the_ type library with that name, skipping alternate names.
176180
pub fn get_type_libraries_by_name(&self, name: &str) -> Array<TypeLibrary> {
177181
let mut count = 0;
178182
let name = name.to_cstr();
@@ -182,6 +186,17 @@ impl Platform {
182186
unsafe { Array::new(result, count, ()) }
183187
}
184188

189+
/// Get the type library with the given name.
190+
///
191+
/// NOTE: This finds the first type library that has the given name, skipping alternate names.
192+
pub fn get_type_library_by_name(&self, name: &str) -> Option<Ref<TypeLibrary>> {
193+
let libraries = self.get_type_libraries_by_name(name);
194+
libraries
195+
.iter()
196+
.find(|lib| lib.name() == name)
197+
.map(|lib| lib.to_owned())
198+
}
199+
185200
pub fn register_os(&self, os: &str) {
186201
let os = os.to_cstr();
187202
unsafe {

0 commit comments

Comments
 (0)