Content-Length: 294547 | pFad | http://github.com/psqlpy-python/rust-postgres-array/commit/c32f38e06cca8d1eb22127576e997f62e6959d15

6D Added from_parts_with_err method to Array · psqlpy-python/rust-postgres-array@c32f38e · GitHub
Skip to content

Commit c32f38e

Browse files
committed
Added from_parts_with_err method to Array
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent a1a242d commit c32f38e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt;
2+
use std::io::{Error, ErrorKind};
23
use std::ops::{Index, IndexMut};
34
use std::slice;
45
use std::vec;
@@ -79,6 +80,22 @@ impl<T> Array<T> {
7980
}
8081
}
8182

83+
pub fn from_parts_with_err(
84+
data: Vec<T>,
85+
dimensions: Vec<Dimension>,
86+
) -> Result<Array<T>, Error> {
87+
if (data.is_empty() && dimensions.is_empty())
88+
|| data.len() as i32 == dimensions.iter().fold(1, |acc, i| acc * i.len)
89+
{
90+
return Err(Error::new(ErrorKind::Other, "size mismatch"));
91+
}
92+
93+
return Ok(Array {
94+
dims: dimensions,
95+
data,
96+
});
97+
}
98+
8299
//github.com/ Creates a new one-dimensional array.
83100
pub fn from_vec(data: Vec<T>, lower_bound: i32) -> Array<T> {
84101
Array {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/psqlpy-python/rust-postgres-array/commit/c32f38e06cca8d1eb22127576e997f62e6959d15

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy