pub struct CapeStringIn<'a> {
interface: &'a *mut ICapeString,
slice: &'a [u16],
}Expand description
CapeStringIn wraps an ICapeString interface pointer as read-only.
Given an reference to an ICapeString interface pointer, this allows getting, but not setting, the string.This is used for strings that are input arguments to methods.
This interface is not typically used directly as pre-generated wrappers provide input strings as str and return values as Result<&str,cobia::COBIAError>. However, for CapeArrayStringIn elements, this interface is used.
A NULL interface pointer is treated as an empty string.
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
assert_eq!(s.as_string(),"idealGasEnthalpy");
}
let mut s1=cobia::CapeStringImpl::from("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Fields§
§interface: &'a *mut ICapeString§slice: &'a [u16]Implementations§
Source§impl<'a> CapeStringIn<'a>
impl<'a> CapeStringIn<'a>
Sourcepub fn new(interface: &'a *mut ICapeString) -> CapeStringIn<'a>
pub fn new(interface: &'a *mut ICapeString) -> CapeStringIn<'a>
Create a new CapeStringIn from an ICapeString interface pointer.
§Arguments
interface- A pointer to an ICapeString interface
§Examples
use cobia::*;
use cobia::prelude::*;
let mut s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
let i_cape_string=s1.as_cape_string_out();
let mut i_cape_string_ptr=(&i_cape_string as *const C::ICapeString).cast_mut(); //normally a pointer to the interface is received
let s = cobia::CapeStringIn::new(&i_cape_string_ptr); //CapeStringIn from *mut C::ICapeString
assert_eq!(s.as_string(),"idealGasEnthalpy");Sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Return the content of the string as a string.
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
assert_eq!(s.as_string(),"idealGasEnthalpy");
}
let mut s1=cobia::CapeStringImpl::from("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Sourcepub fn as_slice(&self) -> &[CapeCharacter] ⓘ
pub fn as_slice(&self) -> &[CapeCharacter] ⓘ
Return the string as a slice
Note that for empty strings, the null terminator may not be included, so check for a zero length slice.
Sourcepub fn eq_ignore_case<T: CapeStringConstProvider>(&self, other: &T) -> bool
pub fn eq_ignore_case<T: CapeStringConstProvider>(&self, other: &T) -> bool
Case insentitive comparison
§Arguments
other- The other string to compare to
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
let s2=cobia::CapeStringImpl::from_string("IDEALGASENTHALPY");
assert_eq!(s.eq_ignore_case(&s2),true);
}
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Sourcepub fn eq<T: CapeStringConstProvider>(&self, other: &T) -> bool
pub fn eq<T: CapeStringConstProvider>(&self, other: &T) -> bool
Case sentitive comparison
§Arguments
other- The other string to compare to
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
let s2=cobia::CapeStringImpl::from_string("IDEALGASENTHALPY");
assert_eq!(s.eq(&s2),false);
let s3=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s.eq(&s3),true);
}
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Trait Implementations§
Source§impl<'a> CapeStringConstProvider for CapeStringIn<'a>
impl<'a> CapeStringConstProvider for CapeStringIn<'a>
Source§fn as_capechar_const_with_length(&self) -> (*const CapeCharacter, CapeSize)
fn as_capechar_const_with_length(&self) -> (*const CapeCharacter, CapeSize)
Return as CapeCharacter const pointer with length
The caller must ensure that the lifetime of the CapeStringImpl is longer than the pointer returned.
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
let (ptr,len)=s.as_capechar_const_with_length(); ///... while ptr is used
assert_eq!(len,16);
}
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Source§fn as_capechar_const(&self) -> *const CapeCharacter
fn as_capechar_const(&self) -> *const CapeCharacter
Return as CapeCharacter const pointer
The caller must ensure that the lifetime of the CapeStringImpl is longer than the pointer returned.
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
let (ptr,len)=s.as_capechar_const_with_length(); ///... while ptr is used
assert_eq!(unsafe{*ptr},'i' as u16);
}
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Source§impl<'a> CapeStringProviderIn for CapeStringIn<'a>
impl<'a> CapeStringProviderIn for CapeStringIn<'a>
Source§fn as_cape_string_in(&self) -> ICapeString
fn as_cape_string_in(&self) -> ICapeString
Source§impl<'a> Debug for CapeStringIn<'a>
impl<'a> Debug for CapeStringIn<'a>
Source§impl<'a> Display for CapeStringIn<'a>
impl<'a> Display for CapeStringIn<'a>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the CapeStringIn error using the given formatter.
§Examples
use cobia::*;
fn test_format(s: &CapeStringIn) {
assert_eq!(format!("{}",s),"idealGasEnthalpy");
}
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
test_format(&CapeStringInFromProvider::from(&s1).as_cape_string_in())Source§impl<'a, T: CapeStringConstProvider> PartialEq<T> for CapeStringIn<'a>
impl<'a, T: CapeStringConstProvider> PartialEq<T> for CapeStringIn<'a>
Source§fn eq(&self, other: &T) -> bool
fn eq(&self, other: &T) -> bool
Compare the CapeStringIn with a string slice or any object that implements CapeStringConstProvider.
§Examples
use cobia::*;
fn test_string(s: &CapeStringIn) {
let s2=cobia::CapeStringImpl::from_string("IDEALGASENTHALPY");
assert_ne!(s,&s2);
let s3=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s,&s3);
}
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
test_string(&CapeStringInFromProvider::from(&s1).as_cape_string_in())