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

Updated to support streaming#1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SilasMarvin merged 6 commits intomasterfromsilas-sdk-streaming
Nov 9, 2023
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Cleaned up rust bridge macros
  • Loading branch information
@SilasMarvin
SilasMarvin committedNov 9, 2023
commit7322c70e7fb366909896e0c8cbdc7dbf45ff04db
17 changes: 8 additions & 9 deletionspgml-sdks/rust-bridge/rust-bridge-macros/src/python.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,33 +18,32 @@ from typing import List, Dict, Optional, Self, Any
pub fn generate_alias_manual(parsed: DeriveInput) -> proc_macro::TokenStream {
let name_ident = format_ident!("{}Python", parsed.ident);
let wrapped_type_ident = parsed.ident;
let (impl_generics, ty_generics, where_clause) = parsed.generics.split_for_impl();

let expanded = quote! {
#[cfg(feature = "python")]
pub struct #name_ident#ty_generics{
pub wrapped: #wrapped_type_ident #ty_generics
pub struct #name_ident {
pub wrapped: #wrapped_type_ident
}

#[cfg(feature = "python")]
impl#impl_genericsrust_bridge::python::CustomInto<#name_ident #ty_generics> for #wrapped_type_ident #ty_generics #where_clause {
fn custom_into(self) -> #name_ident#ty_generics{
impl rust_bridge::python::CustomInto<#name_ident> for #wrapped_type_ident {
fn custom_into(self) -> #name_ident {
#name_ident {
wrapped: self,
}
}
}

#[cfg(feature = "python")]
impl#impl_genericsrust_bridge::python::CustomInto<#wrapped_type_ident #ty_generics> for #name_ident #ty_generics #where_clause {
fn custom_into(self) -> #wrapped_type_ident#ty_generics{
impl rust_bridge::python::CustomInto<#wrapped_type_ident> for #name_ident {
fn custom_into(self) -> #wrapped_type_ident {
self.wrapped
}
}

// From Python to Rust
#[cfg(feature = "python")]
impl#impl_genericspyo3::conversion::FromPyObject<'_> for #name_ident #ty_generics #where_clause {
impl pyo3::conversion::FromPyObject<'_> for #name_ident {
fn extract(obj: &pyo3::PyAny) -> pyo3::PyResult<Self> {
Ok(Self {
wrapped: obj.extract()?
Expand All@@ -54,7 +53,7 @@ pub fn generate_alias_manual(parsed: DeriveInput) -> proc_macro::TokenStream {

// From Rust to Python
#[cfg(feature = "python")]
impl#impl_genericspyo3::conversion::IntoPy<pyo3::PyObject> for #name_ident #ty_generics #where_clause {
impl pyo3::conversion::IntoPy<pyo3::PyObject> for #name_ident {
fn into_py(self, py: pyo3::Python) -> pyo3::PyObject {
use pyo3::conversion::ToPyObject;
self.wrapped.into_py(py)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp