Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0638778

Browse files
style: replace intermediate array andcopy_from_slice with direct array APIs
1 parent21ff4ad commit0638778

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

‎postgres-types/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cidr-02 = { version = "0.2", package = "cidr", optional = true }
5050
cidr-03 = {version ="0.3",package ="cidr",optional =true }
5151
# eui48-04 will stop compiling and support will be removed
5252
# See https://github.com/rust-postgres/rust-postgres/issues/1073
53-
eui48-04 = {version ="0.4",package ="eui48",optional =true }
53+
eui48-04 = {version ="0.4.6",package ="eui48",optional =true }
5454
eui48-1 = {version ="1.0",package ="eui48",optional =true,default-features =false }
5555
geo-types-06 = {version ="0.6",package ="geo-types",optional =true }
5656
geo-types-0_7 = {version ="0.7.8",package ="geo-types",optional =true }

‎postgres-types/src/eui48_04.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ impl<'a> FromSql<'a> for MacAddress {
1616

1717
implToSqlforMacAddress{
1818
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
19-
letmut bytes =[0;6];
20-
bytes.copy_from_slice(self.as_bytes());
21-
types::macaddr_to_sql(bytes, w);
19+
types::macaddr_to_sql(self.to_array(), w);
2220
Ok(IsNull::No)
2321
}
2422

‎postgres-types/src/eui48_1.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ impl<'a> FromSql<'a> for MacAddress {
1616

1717
implToSqlforMacAddress{
1818
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
19-
letmut bytes =[0;6];
20-
bytes.copy_from_slice(self.as_bytes());
21-
types::macaddr_to_sql(bytes, w);
19+
types::macaddr_to_sql(self.to_array(), w);
2220
Ok(IsNull::No)
2321
}
2422

‎postgres-types/src/private.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ pub use bytes::BytesMut;
33
use std::error::Error;
44

55
pubfnread_be_i32(buf:&mut&[u8]) ->Result<i32,Box<dynError +Sync +Send>>{
6-
if buf.len() <4{
7-
returnErr("invalid buffer size".into());
8-
}
9-
letmut bytes =[0;4];
10-
bytes.copy_from_slice(&buf[..4]);
6+
let val = buf
7+
.get(..4)
8+
.ok_or("invalid buffer size")?
9+
.try_into()
10+
.unwrap();
1111
*buf =&buf[4..];
12-
Ok(i32::from_be_bytes(bytes))
12+
Ok(i32::from_be_bytes(val))
1313
}
1414

1515
pubfnread_value<'a,T>(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp