Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/msrv-windows-result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ jobs:
run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Check
run: cargo check -p windows-result --all-features
- name: Check Default Features
run: cargo check -p windows-result
1 change: 1 addition & 0 deletions crates/libs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ windows-interface = { path = "../interface", version = "0.57.0" }
[features]
default = ["std"]
std = []
slim-errors = ["windows-result/slim-errors"]
5 changes: 5 additions & 0 deletions crates/libs/result/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ categories = ["os::windows-apis"]
[features]
default = ["std"]
std = []
# slim-errors reduces the size of Error (and Result<()>) to that of a single HRESULT
slim-errors = []

[lints]
workspace = true
Expand All @@ -21,6 +23,9 @@ workspace = true
default-target = "x86_64-pc-windows-msvc"
targets = []

[dependencies]
static_assertions = "1.0"

[dependencies.windows-targets]
version = "0.52.5"
path = "../targets"
50 changes: 50 additions & 0 deletions crates/libs/result/src/bstr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use super::*;

#[repr(transparent)]
pub struct BasicString(*const u16);

impl BasicString {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn len(&self) -> usize {
if self.0.is_null() {
0
} else {
unsafe { SysStringLen(self.0) as usize }
}
}

pub fn as_wide(&self) -> &[u16] {
let len = self.len();
if len != 0 {
unsafe { core::slice::from_raw_parts(self.as_ptr(), len) }
} else {
&[]
}
}

pub fn as_ptr(&self) -> *const u16 {
if !self.is_empty() {
self.0
} else {
const EMPTY: [u16; 1] = [0];
EMPTY.as_ptr()
}
}
}

impl Default for BasicString {
fn default() -> Self {
Self(core::ptr::null_mut())
}
}

impl Drop for BasicString {
fn drop(&mut self) {
if !self.0.is_null() {
unsafe { SysFreeString(self.0) }
}
}
}
Loading