Language characteristic-based dependency implementation method, device and equipment

By determining business characteristics, generating data structures and specific implementation classes in the Rust language, and using injection and projection to enable containers to implement business characteristics, the problem of high performance and poor maintenance when implementing dependency services is solved, and efficient and maintainable dependency management is achieved.

CN119621028AActive Publication Date: 2025-03-14BEIJING TINGYU TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202510151920.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-12
Publication Date
2025-03-14
Estimated Expiration
2045-02-12

AI Technical Summary

Technical Problem

When implementing services with dependencies, the Rust language has high system performance requirements and poor maintenance.

Method used

By determining the characteristics of the target business and dependent services, generating corresponding data structures and placing them in a container, generating specific implementation classes for the target business and dependent services, and using injection and projection, the container can realize the characteristics of the target business and dependent services.

Benefits of technology

It realizes simple and efficient implementation of dependency services on Rust language, and improves the maintainability of large-scale projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621028A_ABST
    Figure CN119621028A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software, in particular to a dependency implementation method, device and equipment based on language characteristics, and the method specifically comprises the following steps: respectively determining characteristics corresponding to a target service and a dependency service; respectively generating data structure bodies corresponding to the target business and the dependent business, and placing all the data structure bodies in a container; a specific implementation class is generated for the target service and the dependent service, the specific implementation class is generated based on generic parameters, and the generic parameters in the specific implementation class of the target service are further limited to achieve the characteristics of the dependent service; and based on the specific implementation class, enabling the container to implement characteristics corresponding to the target business and the dependent business through injection and projection modes, so as to perform the target business through the container. Therefore, the business of the dependency relationship can be simply and efficiently realized aiming at the Rust language, and meanwhile, the maintainability of large-scale project development is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software technology, and in particular to a method, device and equipment for implementing dependency based on language characteristics. Background Art

[0002] In the software field, for web projects and some large projects, there are often dependencies between multiple businesses. For example, a business method in business A needs to rely on other businesses, such as one or more businesses in business B. In this case, we say that business A depends on business B. Rust, as a non-object-oriented language, is a memory-safe and efficient programming language, but it lacks official or community dependency injection libraries, which means that it needs to implement businesses with dependencies in a cumbersome and complex way, which has high requirements for system performance and poor maintainability. Summary of the invention

[0003] In view of this, the purpose of the present invention is to provide a method, device and equipment for implementing dependencies based on language characteristics, so as to overcome the problems of high system performance requirements and poor maintainability when implementing businesses with dependencies in the current Rust language.

[0004] To achieve the above objectives, the present invention adopts the following technical solutions: In a first aspect, the present application provides a method for implementing dependency based on language characteristics, comprising: Determine characteristics corresponding to the target service and the dependent service respectively, wherein the dependent service is a service on which the target service depends; Generating data structures corresponding to the target business and the dependent business respectively, and placing all the data structures in a container, wherein the data structures store data corresponding to the business; Generate specific implementation classes for the target service and the dependent service, the specific implementation classes are used to implement the characteristics of the corresponding services, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation class of the target service are also restricted to implement the characteristics of the dependent service; Based on the specific implementation class, the container implements the characteristics corresponding to the target business and the dependent business through injection and projection, so as to perform the target business through the container.

[0005] Further, in some embodiments of the present application, generating specific implementation classes for the target service and the dependent service includes: Generate a program code of a specific implementation class corresponding to the target business, the program code is used to obtain a data structure corresponding to the target business to implement a business method defined in a characteristic corresponding to the target business; Generate a program code of a specific implementation class corresponding to the dependent business, and the program code is used to obtain a data structure corresponding to the dependent business to implement a business method defined in a characteristic corresponding to the dependent business.

[0006] Furthermore, in some embodiments of the present application, it also includes: generating an injection method and a projection method for each of the specific implementation classes.

[0007] Further, in some embodiments of the present application, based on the specific implementation class, by injection and projection, the container implements the characteristics corresponding to the target business and the dependent business, so as to perform the target business through the container, including: By using the injection method of the specific implementation class corresponding to the target business, the container is converted into the structure of the specific implementation class of the target business, and based on the specific implementation class of the target business, at least part of the business methods defined in the characteristics corresponding to the target business are implemented and performed.

[0008] Further, in some embodiments of the present application, based on the specific implementation class, by injection and projection, the container implements the characteristics corresponding to the target business and the dependent business, and performs the target business through the container, including: Using the injection method of the specific implementation class of the target business, the container is converted into the structure of the specific implementation class of the target business, and based on the specific implementation class, the part of the business method defined in the characteristics of the target business that does not depend on the dependent business is performed; And then the converted container is converted into the structure of the specific implementation class of the dependent business through the projection method of the specific implementation class of the dependent business, and based on the specific implementation class of the dependent business, the part of the business method defined in the characteristics of the target business that needs to rely on the dependent business is performed.

[0009] Furthermore, in some embodiments of the present application, it also includes: The container is converted into the structure of the specific implementation class of the dependent business by using the injection method of the specific implementation class of the dependent business, and based on the specific implementation class of the dependent business, the business method defined in the characteristics of the dependent business is implemented and performed.

[0010] In a second aspect, the present application provides a language-feature-based dependency implementation device, comprising: A definition module, used to respectively determine characteristics corresponding to a target service and a dependent service, wherein the dependent service is a service on which the target service depends; A first generating module, used to generate data structures corresponding to the target business and the dependent business respectively, and place all the data structures in a container, wherein the data structures store data corresponding to the business; A second generation module is used to generate specific implementation classes for the target business and the dependent business, wherein the specific implementation classes are used to implement the characteristics of the corresponding business, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation class of the target business are also limited to implement the characteristics of the dependent business; The running module is used to enable the container to realize the characteristics corresponding to the target business and the dependent business through injection and projection based on the specific implementation class, so as to perform the target business through the container.

[0011] In a third aspect, the present application provides a language feature-based dependency implementation device, including a processor and a memory, wherein the processor is connected to the memory: Wherein, the processor is used to call and execute the program stored in the memory; The memory is used to store the program, and the program is at least used to execute the above-mentioned language characteristic-based dependency implementation method.

[0012] The present invention relates to the field of software technology, and in particular to a method, device and equipment for implementing dependency based on language characteristics, the method specifically comprising respectively determining the characteristics corresponding to a target business and a dependent business; respectively generating data structures corresponding to the target business and the dependent business, and placing all data structures in a container; generating specific implementation classes for the target business and the dependent business, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation classes of the target business are also limited to implementing the characteristics of the dependent business; based on the specific implementation classes, by injection and projection, the container implements the characteristics corresponding to the target business and the dependent business, so as to perform the target business through the container. In this way, the Rust language can be used to simply and efficiently implement the business of performing dependency relationships, while improving the maintainability of large-scale project development. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0014] Figure 1 It is a flowchart of a method for implementing dependency based on language characteristics provided by an embodiment of the present invention.

[0015] Figure 2 It is a structural diagram of a language characteristic-based dependency implementation device provided by an embodiment of the present invention.

[0016] Figure 3 It is a structural diagram of a language characteristic-based dependency implementation device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0017] To make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.

[0018] Figure 1 This is a flow chart of a method for implementing a dependency based on language characteristics provided by an embodiment of the present invention. Figure 1 , this embodiment may include the following steps: S101. Determine the characteristics corresponding to the target business and the dependent business respectively.

[0019] The dependent business is the business that the target business depends on.

[0020] Specifically, it should be noted that, because of the concept of characteristics, this application is a solution for the Rust language. Of course, for other languages, it can be applied based on the essence of characteristics, that is, memory layout conversion. This application will not describe this in detail. In the Rust language, a trait is an abstract concept used to define shared behaviors, which is similar to the principle of an interface in an object-oriented language. Characteristics in the Rust language are used to define information such as method signatures (but not the program code for the specific implementation method), such as which business methods are included in the target business or dependent business.

[0021] It should be noted that the number of business methods defined in the characteristics corresponding to the target business and the dependent business can be multiple, that is, multiple business methods can be defined in the characteristics of the target business, and multiple business methods can also be defined in the characteristics of the dependent business. In this application, the business that depends on other businesses is called the target business, and the business that the target business depends on is called the dependent business. For example, some business methods in business A need to rely on one or some business methods in business B, so business A can be called the target business and business B can be called the dependent business.

[0022] S102: Generate data structures corresponding to the target business and dependent business respectively, and place all data structures in a container.

[0023] The data structure stores data corresponding to the business.

[0024] Specifically, in this application, the data of each business is stored by a data structure corresponding to the business, for example, the data can be stored by defining a State structure. It should be noted that in this application, the data structure corresponds to the business one-to-one, and a data structure only stores the data required by the corresponding business itself, such as private fields, and does not store data of other businesses.

[0025] S103. Generate specific implementation classes for the target business and dependent businesses.

[0026] The specific implementation class is used to implement the characteristics of the corresponding business, that is, to implement the business methods defined in the characteristics of the corresponding business. The specific implementation class is generated based on generic parameters, and the generic parameters in the specific implementation class of the target business are also limited to implementing the characteristics of the dependent business.

[0027] Specifically, generating specific implementation classes for the target business and the dependent business includes: generating program codes of the specific implementation classes corresponding to the target business, and generating program codes of the specific implementation classes corresponding to the dependent business.

[0028] It can be understood that the program code of the specific implementation class corresponding to the target business is used to obtain the data structure corresponding to the target business and implement the business methods defined in the characteristics corresponding to the target business; the program code of the specific implementation class corresponding to the dependent business is used to obtain the data structure corresponding to the dependent business and implement the business methods defined in the characteristics corresponding to the dependent business.

[0029] In actual applications, the specific implementation class can be an Implement structure, and it is generated based on generic parameters. It can be understood that in the Rust language, generics can be used to generate universal and reusable code without specifying data types. By using generics, functions, structures, enumerations, or traits can operate on different types of data without having to write separate code for each type.

[0030] On this basis, in view of the fact that the target business needs to rely on other businesses, the conditions or behaviors that the generic parameters must meet can be limited based on the type constraints of the generic parameters, that is, when defining the generic parameters, specify which characteristics it must implement, so that it can pass the compilation check smoothly and achieve the purpose of introducing dependencies. In this application, for the generic parameters in the specific implementation class of the target business, when defining it, you can limit its implementation of the characteristics of the dependent business, so that when it is used later, it can pass the compilation check smoothly and introduce dependencies at the same time.

[0031] S104. Based on the specific implementation class, the container is enabled to implement the characteristics corresponding to the target business and the dependent business through injection and projection, so as to perform the target business through the container.

[0032] Specifically, the injection method and projection method of the above specific implementation class can be generated in advance, so that the container can realize the characteristics corresponding to the target business and the dependent business through the injection method and the projection method, so as to perform the target business through the container.

[0033] It can be understood that the function of the injection method is to specify a target object (the container mentioned above during actual runtime) and convert it into the structure of this class. The projection method is to convert the structure of this object (such as the object obtained by injection of the container mentioned above) into the structure of the target class.

[0034] During actual runtime, the structure of the container can be transformed through injection and projection, thereby calling the corresponding specific implementation class to enable the container to implement the corresponding features of the target business and dependent businesses, so as to perform the target business through the container.

[0035] The dependency implementation method based on language characteristics provided by the present invention first determines the characteristics corresponding to the target business and the dependent business respectively; then generates the data structures corresponding to the target business and the dependent business respectively, and places all the data structures in the container; then generates specific implementation classes for the target business and the dependent business, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation classes of the target business are also limited to the characteristics of the dependent business; finally, based on the specific implementation classes, by injection and projection, the container realizes the characteristics corresponding to the target business and the dependent business, so as to perform the target business through the container. In this way, the business of performing dependency relationships can be simply and efficiently realized for the Rust language, while improving the maintainability of large-scale project development.

[0036] It should be noted that, in the present application, since all data structures are placed in a container and all data structures have data corresponding to a business, the data required for all businesses can be accessed through the container.

[0037] In actual applications, you can limit the creation of only one container object in the entire main function. When running globally, you can change the behavior of the container by constantly transforming it into a structure of any class to implement various services, including the following: First, based on the injection method, the business methods defined in the characteristics corresponding to at least part of the target business can be implemented, specifically business methods that do not need to rely on other businesses.

[0038] Specifically, the injection method of the specific implementation class corresponding to the target business can be called to convert the container into the structure of the specific implementation class, and the specific implementation class can be called to implement and perform the business methods defined in the characteristics corresponding to the target business that do not rely on other businesses.

[0039] Second, based on the injection method and the projection method, the business methods defined in the characteristics corresponding to the target business and requiring dependence on other businesses can be implemented.

[0040] Specifically, you can first call the injection method of the specific implementation class corresponding to the target business, convert the container into the structure of the specific implementation class, and call the specific implementation class to implement and perform some business method steps.

[0041] It should be noted that at this time, the structure of the container is in the form of a specific implementation class of the target business. At the same time, because the generic parameters in the specific implementation class of the target business are also limited to implementing the characteristics of the dependent business, it is legal to call the specific implementation class in the dependent business at this time and can pass the compilation check smoothly.

[0042] On this basis, the projection method of the specific implementation class of the dependent business is called to convert the container into the structure of the specific implementation class of the dependent business, and the specific implementation class of the dependent business is called to perform the part of the business method defined in the characteristics of the target business that needs to depend on the dependent business.

[0043] Third, the business methods defined in the characteristics corresponding to the dependent business can be implemented based on the injection method (for the convenience of description, it is assumed in this application that the business methods defined in the characteristics corresponding to the dependent business do not need to rely on other businesses. In actual applications, the dependent business itself may also rely on other businesses. At this time, its specific implementation principle is the same as the above-mentioned target business principle, and will not be repeated here).

[0044] Specifically, the injection method of the specific implementation class corresponding to the dependent business can be called to convert the container into the structure of the specific implementation class, and the specific implementation class can be called to implement and perform the business methods in the characteristics corresponding to the dependent business.

[0045] The dependency implementation method based on language characteristics provided by the present invention transforms the structure of the container by injection and projection, so that it realizes the characteristics of each related business, statically calls the specific implementation class of each business, avoids the runtime overhead of dynamic distribution, and at the same time, through the characteristic restrictions on generic parameters in the specific implementation class, ensures that the code can determine the dependency relationship during compilation, improves the development efficiency of the business with dependency relationships, and improves the runtime performance and system maintainability.

[0046] Based on the same inventive concept, the present application also provides a dependency implementation device based on language characteristics. Figure 2is a schematic diagram of the structure of a language-characteristic-based dependency implementation device provided by an embodiment of the present invention, such as Figure 2 As shown, the device comprises: The definition module 11 is used to determine the characteristics corresponding to the target business and the dependent business respectively, wherein the dependent business is the business that the target business depends on.

[0047] The first generating module 12 is used to generate data structures corresponding to the target business and the dependent business respectively, and place all the data structures in a container, wherein the data structures store data corresponding to the business.

[0048] The second generation module 13 is used to generate specific implementation classes for the target business and dependent businesses, the specific implementation classes are used to implement the characteristics of the corresponding businesses, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation classes of the target business are also limited to implement the characteristics of the dependent businesses.

[0049] The operation module 14 is used to enable the container to realize the characteristics corresponding to the target business and the dependent business through injection and projection based on the specific implementation class, so as to perform the target business through the container.

[0050] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0051] Based on the same inventive concept, the present application also provides a dependency implementation device based on language characteristics, Figure 3 is a schematic diagram of the structure of a language-characteristic-based dependency implementation device provided by an embodiment of the present invention, such as Figure 3 As shown, the device includes a processor 21 and a memory 22, and the processor 21 is connected to the memory 22. The processor 21 is used to call and execute the program stored in the memory 22; the memory 22 is used to store the program, and the program is at least used to execute the language feature-based dependency implementation method in the above embodiment.

[0052] The specific implementation scheme of the language-feature-based dependency implementation device provided in the embodiment of the present application can refer to the implementation scheme of the language-feature-based dependency implementation method in any of the above embodiments, which will not be repeated here.

[0053] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.

[0054] It should be noted that, in the description of the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.

[0055] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.

[0056] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0057] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0058] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0059] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.

[0060] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0061] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A method for implementing dependency based on language characteristics, characterized in that: include: Determine the characteristics corresponding to the target service and the dependent service respectively, wherein the dependent service is the service on which the target service depends; Generating data structures corresponding to the target business and the dependent business respectively, and placing all the data structures in a container, wherein the data structures store data corresponding to the business; Generate specific implementation classes for the target service and the dependent service, the specific implementation classes are used to implement the characteristics of the corresponding services, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation class of the target service are also restricted to implement the characteristics of the dependent service; Based on the specific implementation class, the container implements the characteristics corresponding to the target business and the dependent business through injection and projection, so as to perform the target business through the container.

2. The method for implementing dependency based on language characteristics according to claim 1, characterized in that: The generating of specific implementation classes for the target business and the dependent business includes: Generate a program code of a specific implementation class corresponding to the target business, the program code is used to obtain a data structure corresponding to the target business to implement a business method defined in a characteristic corresponding to the target business; Generate a program code of a specific implementation class corresponding to the dependent business, and the program code is used to obtain a data structure corresponding to the dependent business to implement a business method defined in a characteristic corresponding to the dependent business.

3. The method for implementing dependency based on language characteristics according to claim 1, characterized in that: Also includes: Generate an injection method and a projection method for each of the specific implementation classes.

4. The method for implementing dependency based on language characteristics according to claim 3, characterized in that: The method of enabling the container to realize the characteristics corresponding to the target business and the dependent business by injection and projection based on the specific implementation class, so as to perform the target business through the container, includes: By using the injection method of the specific implementation class corresponding to the target business, the container is converted into the structure of the specific implementation class of the target business, and based on the specific implementation class of the target business, at least part of the business methods defined in the characteristics corresponding to the target business are implemented and performed.

5. The method for implementing dependency based on language characteristics according to claim 1, characterized in that: Based on the specific implementation class, by injection and projection, the container realizes the characteristics corresponding to the target business and the dependent business, and performs the target business through the container, including: Using the injection method of the specific implementation class of the target business, the container is converted into the structure of the specific implementation class of the target business, and based on the specific implementation class, the part of the business method defined in the characteristics of the target business that does not depend on the dependent business is performed; And then the converted container is converted into the structure of the specific implementation class of the dependent business through the projection method of the specific implementation class of the dependent business, and based on the specific implementation class of the dependent business, the part of the business method defined in the characteristics of the target business that needs to rely on the dependent business is performed.

6. The method for implementing dependency based on language characteristics according to claim 1, characterized in that: Also includes: The container is converted into the structure of the specific implementation class of the dependent business by using the injection method of the specific implementation class of the dependent business, and based on the specific implementation class of the dependent business, the business method defined in the characteristics of the dependent business is implemented and performed.

7. A language-based dependency implementation device, characterized in that: include: A definition module, used to respectively determine characteristics corresponding to a target service and a dependent service, wherein the dependent service is a service on which the target service depends; A first generating module, used to generate data structures corresponding to the target business and the dependent business respectively, and place all the data structures in a container, wherein the data structures store data corresponding to the business; A second generation module is used to generate specific implementation classes for the target business and the dependent business, wherein the specific implementation classes are used to implement the characteristics of the corresponding business, wherein the specific implementation classes are generated based on generic parameters, and the generic parameters in the specific implementation class of the target business are also limited to implement the characteristics of the dependent business; The running module is used to enable the container to realize the characteristics corresponding to the target business and the dependent business through injection and projection based on the specific implementation class, so as to perform the target business through the container.

8. A language-based dependency implementation device, characterized in that: The invention comprises a processor and a memory, wherein the processor is connected to the memory: Wherein, the processor is used to call and execute the program stored in the memory; The memory is used to store the program, and the program is at least used to execute the language characteristic-based dependency implementation method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Quick compiling and running method, device and system for micro-service container and electronic equipment

    CN115756763A

  • File acquisition method and device, electronic equipment and readable storage medium

    CN116361242A

  • Front-end construction tool and construction method based on Rust development

    CN117785213A

  • Method for improving SPA application development performance

    CN119292608A

  • Detect application defects by correlating contracts in application dependencies

    US20180129494A1