Skip to content

Commit 91fc89a

Browse files
authored
pr feedback
1 parent 2fd7ec6 commit 91fc89a

File tree

12 files changed

+61
-30
lines changed

12 files changed

+61
-30
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"sdk/core/azure_core_test_macros",
1212
"sdk/core/azure_core_opentelemetry",
1313
"sdk/cosmos/azure_data_cosmos",
14+
"sdk/cosmos/azure_data_cosmos_native",
1415
"sdk/identity/azure_identity",
1516
"sdk/eventhubs/azure_messaging_eventhubs",
1617
"sdk/eventhubs/azure_messaging_eventhubs_checkpointstore_blob",
@@ -22,7 +23,6 @@ members = [
2223
"sdk/template/azure_template",
2324
"sdk/storage/azure_storage_common",
2425
"sdk/storage/azure_storage_blob",
25-
"sdk/cosmos/cosmosclient",
2626
]
2727
exclude = [
2828
"eng/scripts",
File renamed without changes.
File renamed without changes.

sdk/cosmos/cosmosclient/Cargo.toml renamed to sdk/cosmos/azure_data_cosmos_native/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
2-
name = "cosmosclient"
2+
name = "azure_data_cosmos_native"
33
publish = false
4-
description = "C library wrapping the Azure CosmosDB SDK for Rust"
4+
description = "The Cosmos Native Client is a C library, written in Rust but exporting a C-compatible API, that provides a full SDK for Azure Cosmos DB."
55
version = "0.27.0"
66
authors.workspace = true
77
edition.workspace = true
@@ -10,6 +10,7 @@ repository.workspace = true
1010
rust-version.workspace = true
1111

1212
[lib]
13+
name = "cosmosclient"
1314
crate-type = ["cdylib", "staticlib"]
1415

1516
[dependencies]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use std::ffi::{c_char, CStr, CString};
4+
use std::ffi::{c_char, CStr};
55

66
#[macro_use]
77
mod macros;
88

9-
#[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing
109
/// cbindgen:ignore
10+
#[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing
1111
pub static BUILD_IDENTIFIER: &CStr = c_str!(env!("BUILD_IDENTIFIER"));
1212

1313
const VERSION: &CStr = c_str!(env!("CARGO_PKG_VERSION"));
1414

15-
#[no_mangle]
1615
/// Returns a constant C string containing the version of the Cosmos Client library.
16+
#[no_mangle]
1717
pub extern "C" fn cosmosclient_version() -> *const c_char {
1818
VERSION.as_ptr()
1919
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
macro_rules! c_str {
5+
($s:expr) => {
6+
const {
7+
// This does a few funky things to make sure we can stay in a const context
8+
// Which ensures the string is generated as a c-str at compile time
9+
const STR: &str = $s;
10+
const BYTES: [u8; STR.len() + 1] = const {
11+
let mut cstrbuf: [u8; STR.len() + 1] = [0; STR.len() + 1];
12+
let mut i = 0;
13+
// For loops over ranges don't work in const contexts yet.
14+
while i < STR.len() {
15+
cstrbuf[i] = STR.as_bytes()[i];
16+
i += 1;
17+
}
18+
cstrbuf
19+
};
20+
match CStr::from_bytes_with_nul(&BYTES) {
21+
Ok(cstr) => cstr,
22+
Err(_) => panic!("failed to convert value to C string"),
23+
}
24+
}
25+
};
26+
}

0 commit comments

Comments
 (0)