FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rust-postgres-array/src/lib.rs at master · psqlpy-python/rust-postgres-array · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
psqlpy-python
/
rust-postgres-array
Public
forked from
rust-postgres/rust-postgres-array
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rust-postgres-array
/
src
/
lib.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
153 lines (135 loc) · 4.01 KB
Breadcrumbs
rust-postgres-array
/
src
/
lib.rs
Copy path
File metadata and controls
153 lines (135 loc) · 4.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Multi-dimensional arrays with per-dimension specifiable lower bounds
#!
[
doc
(
html_root_url =
"https://docs.rs/postgres_array/0.10"
)
]
#
[
doc
(
inline
)
]
pub
use
crate
::
array
::
Array
;
pub
mod
array
;
mod
impls
;
/// Information about a dimension of an array.
#
[
derive
(
Debug
,
Clone
,
Copy
,
PartialEq
,
Eq
)
]
pub
struct
Dimension
{
/// The length of the dimension.
pub
len
:
i32
,
/// The index of the first element of the dimension.
pub
lower_bound
:
i32
,
}
impl
Dimension
{
fn
shift
(
&
self
,
idx
:
i32
)
->
i32
{
let
offset =
self
.
lower_bound
;
assert
!
(
idx >= offset
,
"out of bounds array access"
)
;
assert
!
(
offset >=
0
|| idx <=
0
||
i32
::
max_value
(
)
-
(
-offset
)
>= idx
,
"out of bounds array access"
)
;
match
idx
.
checked_sub
(
offset
)
{
Some
(
shifted
)
=> shifted
,
None
=>
panic
!
(
"out of bounds array access"
)
,
}
}
}
#
[
cfg
(
test
)
]
mod
tests
{
use
super
::
*
;
#
[
test
]
fn
test_from_vec
(
)
{
let
a =
Array
::
from_vec
(
vec
!
[
0i32
,
1
,
2
]
,
-
1
)
;
assert
!
(
&
[
Dimension
{
len
:
3
,
lower_bound
:
-
1
,
}
,
]
[
..
]
== a
.
dimensions
(
)
)
;
assert_eq
!
(
0
,
a
[
-
1
]
)
;
assert_eq
!
(
1
,
a
[
0
]
)
;
assert_eq
!
(
2
,
a
[
1
]
)
;
}
#
[
test
]
fn
test_into_inner
(
)
{
let
a =
Array
::
from_vec
(
vec
!
[
0i32
,
1
,
2
]
,
-
1
)
;
let
a = a
.
into_inner
(
)
;
assert_eq
!
(
a
.
len
(
)
,
3
)
;
assert_eq
!
(
0
,
a
[
0
]
)
;
assert_eq
!
(
1
,
a
[
1
]
)
;
assert_eq
!
(
2
,
a
[
2
]
)
;
}
#
[
test
]
fn
test_2d_slice_get
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
0i32
,
1
,
2
]
,
-
1
)
;
a
.
wrap
(
1
)
;
assert_eq
!
(
0
,
a
[
(
1
,
-
1
)
]
)
;
assert_eq
!
(
1
,
a
[
(
1
,
0
)
]
)
;
assert_eq
!
(
2
,
a
[
(
1
,
1
)
]
)
;
}
#
[
test
]
#
[
should_panic
]
fn
test_push_wrong_lower_bound
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
1i32
]
,
-
1
)
;
a
.
push
(
Array
::
from_vec
(
vec
!
[
2
]
,
0
)
)
;
}
#
[
test
]
#
[
should_panic
]
fn
test_push_wrong_dims
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
1i32
]
,
-
1
)
;
a
.
wrap
(
1
)
;
a
.
push
(
Array
::
from_vec
(
vec
!
[
1
,
2
]
,
-
1
)
)
;
}
#
[
test
]
#
[
should_panic
]
fn
test_push_wrong_dim_count
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
1i32
]
,
-
1
)
;
a
.
wrap
(
1
)
;
let
mut
b =
Array
::
from_vec
(
vec
!
[
2
]
,
-
1
)
;
b
.
wrap
(
1
)
;
a
.
push
(
b
)
;
}
#
[
test
]
fn
test_push_ok
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
1i32
,
2
]
,
0
)
;
a
.
wrap
(
0
)
;
a
.
push
(
Array
::
from_vec
(
vec
!
[
3
,
4
]
,
0
)
)
;
assert_eq
!
(
1
,
a
[
(
0
,
0
)
]
)
;
assert_eq
!
(
2
,
a
[
(
0
,
1
)
]
)
;
assert_eq
!
(
3
,
a
[
(
1
,
0
)
]
)
;
assert_eq
!
(
4
,
a
[
(
1
,
1
)
]
)
;
}
#
[
test
]
fn
test_3d
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
0i32
,
1
]
,
0
)
;
a
.
wrap
(
0
)
;
a
.
push
(
Array
::
from_vec
(
vec
!
[
2
,
3
]
,
0
)
)
;
a
.
wrap
(
0
)
;
let
mut
b =
Array
::
from_vec
(
vec
!
[
4
,
5
]
,
0
)
;
b
.
wrap
(
0
)
;
b
.
push
(
Array
::
from_vec
(
vec
!
[
6
,
7
]
,
0
)
)
;
a
.
push
(
b
)
;
assert_eq
!
(
0
,
a
[
(
0
,
0
,
0
)
]
)
;
assert_eq
!
(
1
,
a
[
(
0
,
0
,
1
)
]
)
;
assert_eq
!
(
2
,
a
[
(
0
,
1
,
0
)
]
)
;
assert_eq
!
(
3
,
a
[
(
0
,
1
,
1
)
]
)
;
assert_eq
!
(
4
,
a
[
(
1
,
0
,
0
)
]
)
;
assert_eq
!
(
5
,
a
[
(
1
,
0
,
1
)
]
)
;
assert_eq
!
(
6
,
a
[
(
1
,
1
,
0
)
]
)
;
assert_eq
!
(
7
,
a
[
(
1
,
1
,
1
)
]
)
;
}
#
[
test
]
fn
test_mut
(
)
{
let
mut
a =
Array
::
from_vec
(
vec
!
[
1i32
,
2
]
,
0
)
;
a
.
wrap
(
0
)
;
a
[
(
0
,
0
)
]
=
3
;
assert_eq
!
(
3
,
a
[
(
0
,
0
)
]
)
;
}
#
[
test
]
fn
test_display
(
)
{
let
a =
Array
::
from_vec
(
vec
!
[
0i32
,
1
,
2
,
3
,
4
]
,
1
)
;
assert_eq
!
(
"{0,1,2,3,4}"
,
&
format!
(
"{}"
,
a
)
)
;
let
a =
Array
::
from_vec
(
vec
!
[
0i32
,
1
,
2
,
3
,
4
]
,
-
3
)
;
assert_eq
!
(
"[-3:1]={0,1,2,3,4}"
,
&
format!
(
"{}"
,
a
)
)
;
let
mut
a =
Array
::
from_vec
(
vec
!
[
1i32
,
2
,
3
]
,
3
)
;
a
.
wrap
(
-
2
)
;
a
.
push
(
Array
::
from_vec
(
vec
!
[
4
,
5
,
6
]
,
3
)
)
;
a
.
wrap
(
1
)
;
assert_eq
!
(
"[1:1][-2:-1][3:5]={{{1,2,3},{4,5,6}}}"
,
&
format!
(
"{}"
,
a
)
)
;
let
a
:
Array
<
String
>
=
Array
::
from_parts
(
vec
!
[
]
,
vec
!
[
]
)
;
assert_eq
!
(
"{}"
,
&
format!
(
"{}"
,
a
)
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL