[][src]Struct sibyl::Varchar

pub struct Varchar<'e> { /* fields omitted */ }

Represents Oracle character types - VARCHAR, LONG, etc.

Methods

impl<'e> Varchar<'e>[src]

pub fn from_string(text: &str, env: &'e dyn Env) -> Result<Self>[src]

Returns a new Varchar constructed from the specified string

Example

use sibyl as oracle;

let env = oracle::env()?;
let src = "Hello, World!";
let txt = oracle::Varchar::from_string(src, &env)?;

assert!(13 <= txt.capacity()?);

let len = txt.len();
assert_eq!(13, len);

let res = unsafe { std::slice::from_raw_parts(txt.as_raw_ptr(), len as usize) };
let res = String::from_utf8_lossy(res);

assert_eq!(src, res);

pub fn from_varchar(other: &'e Varchar) -> Result<Self>[src]

Returns a new Varchar constructed with the copy of the date from the other Varchar.

Example

use sibyl as oracle;

let env = oracle::env()?;
let src = "Hello, World!";
let inp = oracle::Varchar::from_string(src, &env)?;
let txt = oracle::Varchar::from_varchar(&inp)?;

let len = txt.len();
assert_eq!(13, len);

let res = unsafe { std::slice::from_raw_parts(txt.as_raw_ptr(), len as usize) };
let res = String::from_utf8_lossy(res);
assert_eq!(src, res);

pub fn with_capacity(size: usize, env: &'e dyn Env) -> Result<Self>[src]

Returns a new Varchar with the memory allocated for the txt data.

pub fn set(&mut self, text: &str) -> Result<()>[src]

Updates the content of self to text

Example

use sibyl as oracle;

let env = oracle::env()?;
let mut txt = oracle::Varchar::with_capacity(0, &env)?;
let src = "Hello, World!";
txt.set(src)?;

let len = txt.len();
assert_eq!(13, len);

let res = unsafe { std::slice::from_raw_parts(txt.as_raw_ptr(), len as usize) };
let res = String::from_utf8_lossy(res);
assert_eq!(src, res);

pub fn len(&self) -> usize[src]

Returns the size of the string in bytes.

pub fn capacity(&self) -> Result<usize>[src]

Returns the allocated size of string memory in bytes

pub fn resize(&mut self, new_size: usize) -> Result<()>[src]

Changes the size of the memory of a string in the object cache. Content of the string is not preserved.

Example

use sibyl as oracle;

let env = oracle::env()?;
let mut txt = oracle::Varchar::with_capacity(10, &env)?;
let cap = txt.capacity()?;
assert!(cap >= 10);

txt.resize(20);
let cap = txt.capacity()?;
assert!(cap >= 20);

txt.resize(0);
// Cannot not ask for capacity after resize to 0.
// Yes, it works for OCIRaw, but not here.
let res = txt.capacity();
assert!(res.is_err());
if let Err( err ) = res {
    assert_eq!(err, oracle::Error::Oracle((21500,"internal error code...".to_string())));
}

txt.resize(16);
let cap = txt.capacity()?;
assert!(cap >= 16);

pub fn as_raw_ptr(&self) -> *mut u8[src]

Returns unsafe pointer to the string data

Trait Implementations

impl<'_> ToSql for Varchar<'_>[src]

impl<'_> ToSqlOut for Varchar<'_>[src]

fn set_len(&mut self, _new_len: usize)[src]

Called to set the received data length (always less than the initial capacity)

impl<'_> Drop for Varchar<'_>[src]

impl<'_> ToString for Varchar<'_>[src]

Auto Trait Implementations

impl<'e> !Send for Varchar<'e>

impl<'e> !Sync for Varchar<'e>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]