Struct CslStringList

Source
pub struct CslStringList { /* private fields */ }
Expand description

Wraps a gdal_sys::CSLConstList (a.k.a. char **papszStrList).

This data structure (a null-terminated array of null-terminated strings) is used throughout GDAL to pass KEY=VALUE-formatted options to various functions.

§Example

There are a number of ways to populate a CslStringList:

use gdal::cpl::{CslStringList, CslStringListEntry};

let mut sl1 = CslStringList::new();
sl1.set_name_value("NUM_THREADS", "ALL_CPUS").unwrap();
sl1.set_name_value("COMPRESS", "LZW").unwrap();
sl1.add_string("MAGIC_FLAG").unwrap();

let sl2: CslStringList = "NUM_THREADS=ALL_CPUS COMPRESS=LZW MAGIC_FLAG".parse().unwrap();
let sl3 = CslStringList::from_iter(["NUM_THREADS=ALL_CPUS", "COMPRESS=LZW", "MAGIC_FLAG"]);
let sl4 = CslStringList::from_iter([
    CslStringListEntry::from(("NUM_THREADS", "ALL_CPUS")),
    CslStringListEntry::from(("COMPRESS", "LZW")),
    CslStringListEntry::from("MAGIC_FLAG")
]);

assert_eq!(sl1.to_string(), sl2.to_string());
assert_eq!(sl2.to_string(), sl3.to_string());
assert_eq!(sl3.to_string(), sl4.to_string());

One CslStringList can be combined with another:

use gdal::cpl::CslStringList;
let mut base: CslStringList = "NUM_THREADS=ALL_CPUS COMPRESS=LZW".parse().unwrap();
let debug: CslStringList = "CPL_CURL_VERBOSE=YES CPL_DEBUG=YES".parse().unwrap();
base.extend(&debug);

assert_eq!(base.fetch_name_value("CPL_DEBUG"), Some("YES".into()));

See the CSL* GDAL functions for more details.

Implementations§

Source§

impl CslStringList

Source

pub fn new() -> Self

Creates an empty GDAL string list.

Source

pub fn add_name_value(&mut self, name: &str, value: &str) -> Result<()>

Assigns value to the key name without checking for a pre-existing assignments.

Returns Ok(()) on success, or Err(GdalError::BadArgument) if name has non-alphanumeric characters or value has newline characters.

See: CSLAddNameValue for details.

Source

pub fn set_name_value(&mut self, name: &str, value: &str) -> Result<()>

Assigns value to the key name, overwriting any existing assignment to name.

Returns Ok(()) on success, or Err(GdalError::BadArgument) if name has non-alphanumeric characters or value has newline characters.

See: CSLSetNameValue for details.

Source

pub fn add_string(&mut self, value: &str) -> Result<()>

Adds a copy of the string slice value to the list.

Returns Ok(()) on success, Err(GdalError::FfiNulError) if value cannot be converted to a C string, e.g. value contains a 0 byte, which is used as a string termination sentinel in C.

See: CSLAddString

Source

pub fn add_entry(&mut self, entry: &CslStringListEntry) -> Result<()>

Adds the contents of a CslStringListEntry to self.

Returns Err(GdalError::BadArgument) if entry doesn’t not meet entry restrictions as described by CslStringListEntry.

Source

pub fn fetch_name_value(&self, name: &str) -> Option<String>

Looks up the value corresponding to name.

See CSLFetchNameValue for details.

Source

pub fn find_string(&self, value: &str) -> Option<usize>

Perform a case insensitive search for the given string

Returns Some(usize) of value index position, or None if not found.

See: CSLFindString for details.

Source

pub fn find_string_case_sensitive(&self, value: &str) -> Option<usize>

Perform a case sensitive search for the given string

Returns Some(usize) of value index position, or None if not found.

See: CSLFindString for details.

Source

pub fn partial_find_string(&self, fragment: &str) -> Option<usize>

Perform a case sensitive partial string search indicated by fragment.

Returns Some(usize) of value index position, or None if not found.

See: CSLPartialFindString for details.

Source

pub fn get_field(&self, index: usize) -> Option<CslStringListEntry>

Fetch the CslStringListEntry for the entry at the given index.

Returns None if index is out of bounds, Some(entry) otherwise.

Source

pub fn len(&self) -> usize

Determine the number of entries in the list.

See: CSLCount for details.

Source

pub fn is_empty(&self) -> bool

Determine if the list has any values

Source

pub fn iter(&self) -> CslStringListIterator<'_>

Get an iterator over the name=value elements of the list.

Source

pub fn as_ptr(&self) -> CSLConstList

Get the raw pointer to the underlying data.

Source

pub fn into_ptr(self) -> CSLConstList

Get the raw pointer to the underlying data, passing ownership (and responsibility for freeing) to the the caller.

Trait Implementations§

Source§

impl Clone for CslStringList

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CslStringList

Source§

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

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

impl Default for CslStringList

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for CslStringList

Source§

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

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

impl Drop for CslStringList

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Extend<CslStringListEntry> for CslStringList

Source§

fn extend<T: IntoIterator<Item = CslStringListEntry>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a> FromIterator<&'a str> for CslStringList

Source§

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<CslStringListEntry> for CslStringList

Source§

fn from_iter<T: IntoIterator<Item = CslStringListEntry>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<String> for CslStringList

Source§

fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for CslStringList

Parse a space-delimited string into a CslStringList.

See CSLTokenizeString for details

Source§

type Err = GdalError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<'a> IntoIterator for &'a CslStringList

Source§

type Item = CslStringListEntry

The type of the elements being iterated over.
Source§

type IntoIter = CslStringListIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl TryFrom<RasterizeOptions> for CslStringList

Source§

type Error = GdalError

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

fn try_from(value: RasterizeOptions) -> Result<CslStringList>

Performs the conversion.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.