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

Commitd206100

Browse files
committed
Use py_class macro
1 parent38c43e0 commitd206100

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

‎vm/src/stdlib/socket.rs‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -432,21 +432,19 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
432432

433433
ctx.set_attr(&py_mod,"SOCK_DGRAM", ctx.new_int(SocketKind::Dgramasi32));
434434

435-
let socket ={
436-
let socket = ctx.new_class("socket", ctx.object());
437-
ctx.set_attr(&socket,"__new__", ctx.new_rustfunc(socket_new));
438-
ctx.set_attr(&socket,"connect", ctx.new_rustfunc(socket_connect));
439-
ctx.set_attr(&socket,"recv", ctx.new_rustfunc(socket_recv));
440-
ctx.set_attr(&socket,"send", ctx.new_rustfunc(socket_send));
441-
ctx.set_attr(&socket,"bind", ctx.new_rustfunc(socket_bind));
442-
ctx.set_attr(&socket,"accept", ctx.new_rustfunc(socket_accept));
443-
ctx.set_attr(&socket,"listen", ctx.new_rustfunc(socket_listen));
444-
ctx.set_attr(&socket,"close", ctx.new_rustfunc(socket_close));
445-
ctx.set_attr(&socket,"getsockname", ctx.new_rustfunc(socket_getsockname));
446-
ctx.set_attr(&socket,"sendto", ctx.new_rustfunc(socket_sendto));
447-
ctx.set_attr(&socket,"recvfrom", ctx.new_rustfunc(socket_recvfrom));
448-
socket
449-
};
435+
let socket =py_class!(ctx,"socket", ctx.object(),{
436+
"__new__" => ctx.new_rustfunc(socket_new),
437+
"connect" => ctx.new_rustfunc(socket_connect),
438+
"recv" => ctx.new_rustfunc(socket_recv),
439+
"send" => ctx.new_rustfunc(socket_send),
440+
"bind" => ctx.new_rustfunc(socket_bind),
441+
"accept" => ctx.new_rustfunc(socket_accept),
442+
"listen" => ctx.new_rustfunc(socket_listen),
443+
"close" => ctx.new_rustfunc(socket_close),
444+
"getsockname" => ctx.new_rustfunc(socket_getsockname),
445+
"sendto" => ctx.new_rustfunc(socket_sendto),
446+
"recvfrom" => ctx.new_rustfunc(socket_recvfrom),
447+
});
450448
ctx.set_attr(&py_mod,"socket", socket.clone());
451449

452450
py_mod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp