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
impl CslStringList
Sourcepub fn add_name_value(&mut self, name: &str, value: &str) -> Result<()>
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.
Sourcepub fn set_name_value(&mut self, name: &str, value: &str) -> Result<()>
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.
Sourcepub fn add_string(&mut self, value: &str) -> Result<()>
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
Sourcepub fn add_entry(&mut self, entry: &CslStringListEntry) -> Result<()>
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.
Sourcepub fn fetch_name_value(&self, name: &str) -> Option<String>
pub fn fetch_name_value(&self, name: &str) -> Option<String>
Looks up the value corresponding to name.
See CSLFetchNameValue
for details.
Sourcepub fn find_string(&self, value: &str) -> Option<usize>
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.
Sourcepub fn find_string_case_sensitive(&self, value: &str) -> Option<usize>
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.
Sourcepub fn partial_find_string(&self, fragment: &str) -> Option<usize>
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.
Sourcepub fn get_field(&self, index: usize) -> Option<CslStringListEntry>
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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Determine the number of entries in the list.
See: CSLCount for details.
Sourcepub fn iter(&self) -> CslStringListIterator<'_> ⓘ
pub fn iter(&self) -> CslStringListIterator<'_> ⓘ
Get an iterator over the name=value elements of the list.
Sourcepub fn as_ptr(&self) -> CSLConstList
pub fn as_ptr(&self) -> CSLConstList
Get the raw pointer to the underlying data.
Sourcepub fn into_ptr(self) -> CSLConstList
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
impl Clone for CslStringList
Source§impl Debug for CslStringList
impl Debug for CslStringList
Source§impl Default for CslStringList
impl Default for CslStringList
Source§impl Display for CslStringList
impl Display for CslStringList
Source§impl Drop for CslStringList
impl Drop for CslStringList
Source§impl Extend<CslStringListEntry> for CslStringList
impl Extend<CslStringListEntry> for CslStringList
Source§fn extend<T: IntoIterator<Item = CslStringListEntry>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = CslStringListEntry>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<'a> FromIterator<&'a str> for CslStringList
impl<'a> FromIterator<&'a str> for CslStringList
Source§impl FromIterator<CslStringListEntry> for CslStringList
impl FromIterator<CslStringListEntry> for CslStringList
Source§fn from_iter<T: IntoIterator<Item = CslStringListEntry>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = CslStringListEntry>>(iter: T) -> Self
Source§impl FromIterator<String> for CslStringList
impl FromIterator<String> for CslStringList
Source§impl FromStr for CslStringList
Parse a space-delimited string into a CslStringList.
impl FromStr for CslStringList
Parse a space-delimited string into a CslStringList.
See CSLTokenizeString for details