Struct CapeStringIn

Source
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>

Source

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");
Source

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())
Source

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.

Source

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())
Source

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())
Source

pub fn is_empty(&self) -> bool

Check empty

§Examples
use cobia::*;

fn test_empty(s: &CapeStringIn) {
	assert_eq!(s.is_empty(),true);
}
 
let s1=cobia::CapeStringImpl::new();
test_empty(&CapeStringInFromProvider::from(&s1).as_cape_string_in())

Trait Implementations§

Source§

impl<'a> CapeStringConstProvider for CapeStringIn<'a>

Source§

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

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>

Source§

fn as_cape_string_in(&self) -> ICapeString

Convert to ICapeString
Source§

impl<'a> Debug for CapeStringIn<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for CapeStringIn<'a>

Source§

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>

Source§

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())
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<'a> Freeze for CapeStringIn<'a>

§

impl<'a> RefUnwindSafe for CapeStringIn<'a>

§

impl<'a> !Send for CapeStringIn<'a>

§

impl<'a> !Sync for CapeStringIn<'a>

§

impl<'a> Unpin for CapeStringIn<'a>

§

impl<'a> UnwindSafe for CapeStringIn<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.