1#pragma once
2
3/* Generated with cbindgen:0.26.0 */
4
5#include <cstdarg>
6#include <cstdint>
7#include <cstdlib>
8#include <ostream>
9#include <new>
10namespace slint { struct SharedString; }
11
12namespace slint {
13namespace cbindgen_private {
14
15/// That's basically the same as `&'a [T]` but `repr(C)`
16///
17/// Can be constructed from a slice using the from trait.
18///
19/// ```
20/// use i_slint_core::slice::Slice;
21/// let x = Slice::from_slice(&[1, 2, 3]);
22/// assert_eq!(x.len(), 3);
23/// assert_eq!(x[1], 2);
24/// let slice : &'static [u32] = x.as_slice();
25/// ```
26///
27/// Comparing two Slice compare their pointer, not the content.
28/// ```
29/// use i_slint_core::slice::Slice;
30/// let a = Slice::from_slice(&[1, 2, 3]);
31/// let slice = [1, 2, 3, 4];
32/// let b = Slice::from(&slice[..3]);
33/// // two slice coming from the same pointer are equal.
34/// assert_eq!(b, Slice::from(&slice[..3]));
35/// // these are different because the pointers are different
36/// assert_ne!(a, b);
37/// // use as_slice to compare the contents
38/// assert_eq!(a.as_slice(), b.as_slice());
39/// ```
40template<typename T>
41struct Slice {
42 /// Invariant, this is a valid slice of len `len`
43 T *ptr;
44 uintptr_t len;
45 const T &operator[](int i) const { return ptr[i]; }
46 /// Note: this doesn't initialize Slice properly, but we need to keep the struct as compatible with C
47 constexpr Slice() = default;
48 /// Rust uses a NonNull, so even empty slices shouldn't use nullptr
49 constexpr Slice(const T *ptr, uintptr_t len) : ptr(ptr ? const_cast<T*>(ptr) : reinterpret_cast<T*>(sizeof(T))), len(len) {}
50
51};
52
53extern "C" {
54
55/// Returns a nul-terminated pointer for this string.
56/// The returned value is owned by the string, and should not be used after any
57/// mutable function have been called on the string, and must not be freed.
58const char *slint_shared_string_bytes(const SharedString *ss);
59
60/// Destroy the shared string
61void slint_shared_string_drop(const SharedString *ss);
62
63/// Increment the reference count of the string.
64/// The resulting structure must be passed to slint_shared_string_drop
65void slint_shared_string_clone(SharedString *out, const SharedString *ss);
66
67/// Safety: bytes must be a valid utf-8 string of size len without null inside.
68/// The resulting structure must be passed to slint_shared_string_drop
69void slint_shared_string_from_bytes(SharedString *out, const char *bytes, uintptr_t len);
70
71/// Create a string from a number.
72/// The resulting structure must be passed to slint_shared_string_drop
73void slint_shared_string_from_number(SharedString *out, double n);
74
75/// Append some bytes to an existing shared string
76///
77/// bytes must be a valid utf8 array of size `len`, without null bytes inside
78void slint_shared_string_append(SharedString *self_, const char *bytes, uintptr_t len);
79
80} // extern "C"
81
82} // namespace cbindgen_private
83} // namespace slint
84

source code of slint/target/debug/build/slint-cpp-d3acc71f258707cf/out/generated_include/slint_string_internal.h