Skip to content

Commit 4f2176d

Browse files
committed
New owned map creation initilises api
1 parent 413d022 commit 4f2176d

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"lldb.showDisassembly": "auto",
33
"lldb.dereferencePointers": true,
4-
"lldb.consoleMode": "commands"
4+
"lldb.consoleMode": "commands",
5+
"rust-analyzer.cargo.features": "all"
56
}

rustsynth-derive/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use syn::{self, parse_macro_input, DeriveInput, Ident, ItemMod};
44

55
/// Derive macro generating an impl of `rustsynth::map::IntoOwnedMap`.
66
///
7+
/// This macro automatically generates an implementation that converts a struct
8+
/// into a VapourSynth map by storing each field as a map entry.
9+
///
710
/// # Example
811
/// ```
912
/// use rustsynth::IntoOwnedMap;
@@ -43,10 +46,14 @@ fn impl_map_macro(ast: &syn::DeriveInput) -> TokenStream {
4346
};
4447
let gen = quote! {
4548
impl rustsynth::map::IntoOwnedMap for #name {
46-
fn into_owned_map<'elem>(self) -> rustsynth::map::OwnedMap<'elem> {
47-
let mut map = rustsynth::map::OwnedMap::new();
49+
fn into_owned_map<'elem>(self) -> rustsynth::map::Map<'elem> {
50+
// Ensure API is initialized before creating a map
51+
// This is required for Map::new() to work correctly
52+
let mut map = rustsynth::map::Map::new()
53+
.expect("Failed to create map - ensure VapourSynth API is initialized with init_api() or use within a VapourSynth plugin context");
4854
#(
49-
map.set(stringify!(#fields), &self.#fields).unwrap();
55+
map.set(stringify!(#fields), &self.#fields)
56+
.expect(&format!("Failed to set field '{}' in map", stringify!(#fields)));
5057
)*
5158
map
5259
}

rustsynth/src/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn handle_append_prop_error(error: i32) -> MapResult<()> {
107107
impl<'elem> Map<'elem> {
108108
/// Creates a new owned map.
109109
pub fn new() -> MapResult<Self> {
110-
let handle = unsafe { API::get_cached().create_map() };
110+
let handle = API::get().ok_or(MapError::CreationFailed)?.create_map();
111111
let handle = NonNull::new(handle).ok_or(MapError::CreationFailed)?;
112112

113113
Ok(Self {

0 commit comments

Comments
 (0)