wasefire-applet-api-desc 0.2.3

Description of the Wasefire applet API
Documentation
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::*;

#[cfg(feature = "api-store-fragment")]
mod fragment;

pub(crate) fn new() -> Item {
    let docs = docs! {
        /// Persistent storage operations.
    };
    let name = "store".into();
    let items = vec![
        #[cfg(feature = "api-store")]
        item! {
            /// Inserts an entry in the store.
            ///
            /// If an entry for that key was already present, it is overwritten.
            fn insert "si" {
                /// Key of the entry.
                ///
                /// This must be smaller than 4096.
                key: usize,

                /// Value of the entry.
                ptr: *const u8,

                /// Length of the value.
                len: usize,
            } -> ()
        },
        #[cfg(feature = "api-store")]
        item! {
            /// Removes an entry from the store.
            ///
            /// This is not an error if no entry is present. This is simply a no-op in that case.
            fn remove "sr" {
                /// Key of the entry.
                key: usize,
            } -> ()
        },
        #[cfg(feature = "api-store")]
        item! {
            /// Finds an entry in the store, if any.
            ///
            /// Returns whether an entry was found.
            ///
            /// This is an [allocating function](crate#allocating-memory).
            fn find "sf" {
                /// Key of the entry to find.
                key: usize,

                /// Where to write the value of the entry, if found.
                ptr: *mut *mut u8,

                /// Where to write the length of the value, if found.
                len: *mut usize,
            } -> bool
        },
        #[cfg(feature = "api-store")]
        item! {
            /// Returns the unordered keys of the entries in the store.
            ///
            /// This is an [allocating function](crate#allocating-memory) returning the number of
            /// keys (thus half the number of allocated bytes).
            fn keys "sk" {
                /// Where to write the keys as an array of u16.
                ptr: *mut *mut u8,
            } -> usize
        },
        #[cfg(feature = "api-store")]
        item! {
            /// Clears the store, removing all entries.
            fn clear "sc" {} -> ()
        },
        #[cfg(feature = "api-store-fragment")]
        fragment::new(),
    ];
    Item::Mod(Mod { docs, name, items })
}