sapling/eden/scm/lib/backingstore/cbindgen.toml
Zeyi (Rice) Fan 9328adfaf9 backingstore: add Tree and TreeEntry Rust structs to pass manifest
Summary: This diff adds Rust structs to represent the data EdenFS wants from a manifest so we can pass these to EdenFS.

Reviewed By: wez

Differential Revision: D18365440

fbshipit-source-id: b474ceb698d9230e1b02c2cce1bec2a32bd3f94f
2019-11-19 18:01:23 -08:00

96 lines
2.3 KiB
TOML

language = "C++"
# The "\u0065" in the header is simply the letter 'e'. This trick is to prevent
# our tools from marking this file as generated file.
header = """/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*
* This file is generated with cbindgen. Please run `./tools/cbindgen.sh` to
* update this file.
*
* @gen\u0065rated <<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>
*
*/
// The generated functions are exported from this Rust library
// @dep=:backingstore
#pragma once
#include <memory>
#include <functional>
#include <folly/Range.h>
extern "C" void rust_cfallible_free_error(char *ptr);
// MSVC toolchain dislikes having template in `extern "C"` functions. So we will
// have to use void pointer here. Cbindgen does not support generating code like
// this since it's kinda a special case so we manually generate this struct.
struct RustCFallibleBase {
void *value;
char *error;
};
// Some Rust functions will have the return type `RustCFallibleBase`, and we
// have this convenient struct to help C++ code to consume the returned
// struct. This is the only way to use the returned `RustCFallibleBase` from
// Rust, and the user must provide a `Deleter` to correctly free the pointer
// returned from Rust.
template <typename T, typename Deleter = std::function<void(T*)>>
class RustCFallible {
private:
std::unique_ptr<T, std::function<void(T*)>> ptr_;
char* error_;
public:
RustCFallible(RustCFallibleBase&& base, Deleter deleter)
: ptr_(reinterpret_cast<T*>(base.value), deleter), error_(base.error) {}
bool isError() const {
return error_ != nullptr;
}
char* getError() {
return error_;
}
T* get() {
return ptr_.get();
}
std::unique_ptr<T, Deleter> unwrap() {
return std::move(ptr_);
}
~RustCFallible() {
if (error_ != nullptr) {
rust_cfallible_free_error(error_);
}
unwrap();
}
};
"""
[export]
prefix= "Rust"
exclude = ["CFallible"]
include = ["Tree", "TreeEntry", "TreeEntryType"]
[export.rename]
"CFallible" = "CFallibleBase"
[export.body]
"CBytes" = """
folly::ByteRange asByteRange() const {
return folly::ByteRange(ptr, len);
}
operator folly::ByteRange() const {
return asByteRange();
}
"""